产品动态
产品近期公告
关于 TRTC Live 正式上线的公告
关于TRTC Conference 正式版上线的公告
Conference 商业化版本即将推出
关于多人音视频 Conference 开启内测公告
关于音视频通话 Call 正式版上线的公告
关于腾讯云音视频终端 SDK 播放升级及新增授权校验的公告
关于 TRTC 应用订阅套餐服务上线的相关说明
enablePayloadPrivateEncryption方法启用私有加密,请参见以下步骤分别生成并设置密钥和盐。// 随机生成一个 string 型、16 字节或 32 字节的密钥,并将该密钥传入 TRTCPayloadPrivateEncrypopenssl rand -hex 16a2e898d07a304246044f899a16123263openssl rand -hex 328301281ec074a4cb2bd31aa40ad795d15a190d56fb73408db91244c5a3f90a2d
enablePayloadPrivateEncryption时传入 SDK。// 随机生成一个 Base64 编码、32 字节的盐,并将该盐传入 TRTCPayloadPrivateEncryptionConfigopenssl rand -base64 323ZZ0nV/rDVUzTa6tXyz+F7rrUYIcxRqX5fiUto/FbZA=
enablePayloadPrivateEncryption时传入SDK。#include <boost/archive/iterators/binary_from_base64.hpp> #include <boost/archive/iterators/transform_width.hpp> #include <string> #include <vector> #include <algorithm> #include <stdint.h> #include "ITRTCCloud.h" liteav::ITRTCCloud* trtcCloud; // 获取在服务端生成的密钥和盐 bool getKeyAndSaltFromSever(std::string& secret, std::string& saltBase64); // 声明一个工具函数,用于将 Base64 转换成 uint8_t bool decodeBase64(const std::string& input, std::vector<uint8_t>& output) { output.resize(32); typedef boost::archive::iterators::transform_width<boost::archive::iterators::binary_from_base64<std::string::const_iterator>, 8, 6> Base64DecodeIterator; try { std::copy(Base64DecodeIterator(input.begin()), Base64DecodeIterator(input.end()), output.begin()); } catch (...) { return false; } return true; } int enablePayloadPrivateEncryption() { std::string key; std::string saltBase64; std::vector<uint8_t> salt; if(!getKeyAndSaltFromSever(key, saltBase64)) return -1; if(trtcCloud && decodeBase64(saltBase64, salt)) { liteav::TRTCPayloadPrivateEncryptionConfig config; // 设置加密算法为 TRTCEncryptionAlgorithmAes128Gcm config.encryptionAlgorithm = TRTCEncryptionAlgorithm::TRTCEncryptionAlgorithmAes128Gcm; // 设置密钥 config.encryptionKey = key.c_str(); // 设置盐 memcpy(config.encryptionSalt, salt.data(), sizeof(config.encryptionSalt)); // 启用私有加密 return trtcCloud->enablePayloadPrivateEncryption(true, config); } return -1; }
文档反馈