问题如标题
声网有这么个配置
/**
* SDK 加密配置
*/
fun enableEncryption(
from: ContactUserId,
to: ContactUserId,
randomBytes: ByteArray,
): Boolean {
val material = buildString {
append(from.teamId)
append(from.userId)
append(to.teamId)
append(to.userId)
append(bytesToHex(randomBytes))
}.toByteArray()
val bytes = smCipher.sm3KDF(material, 64)
val secretKey = bytes.copyOfRange(0, 32)
val salt = bytes.copyOfRange(32, 64)
val config = EncryptionConfig()
config.encryptionMode = EncryptionConfig.EncryptionMode.SM4_128_ECB
// 声网底层处理 hex String 时大小写敏感,这里与其他端保持统一,小写
config.encryptionKey = bytesToHex(secretKey)
System.arraycopy(
salt,
0,
config.encryptionKdfSalt,
0,
config.encryptionKdfSalt.size
)
val result = rtcEngine?.enableEncryption(true, config)
Timber.d("$tag enableEncryption: $result")
return result == 0
}