基于AES加密的RTSP/RTMP多路转发设计方案

很多开发者最近咨询我们,除了我们Windows推送端采集编码的音视频数据可以加密外,其他RTSP/RTMP流如果想更安全的转推到RTMP服务器或相应CDN改怎么办?

实际上,我们在做RTMP整体加密方案的时候已经考虑到这种情况,SmartStreamRelayDemo在拉取RTSP或RTMP流,转推RTMP的时候,可以选择加密视频,加密音频或音视频都加密,废话不多说,参看代码:

bool nt_stream_relay_wrapper::StartPush(const std::string& url)
{
	if ( is_pushing_ ) return false; if ( url.empty() ) return false; if ( !OpenPushHandle() ) return false; auto push_handle = GetPushHandle(); ASSERT(push_handle != nullptr); ASSERT(push_api_ != NULL); if ( NT_ERC_OK != push_api_->SetURL(push_handle, url.c_str(), NULL) ) { if ( !is_started_rtsp_stream_ ) { push_api_->Close(push_handle); SetPushHandle(nullptr); } return false; } // 加密测试 +++ push_api_->SetRtmpEncryptionOption(push_handle, url.c_str(), 1, 1); NT_BYTE test_key[16] = {'1', '2', '3'}; push_api_->SetRtmpEncryptionKey(push_handle, url.c_str(), test_key, 16); // 加密测试 -- if ( NT_ERC_OK != push_api_->StartPublisher(push_handle, NULL) ) { if ( !is_started_rtsp_stream_ ) { push_api_->Close(push_handle); SetPushHandle(nullptr); } return false; } // // test push rtsp ++ // push_api_->SetPushRtspTransportProtocol(push_handle, 1); // // push_api_->SetPushRtspTransportProtocol(push_handle, 2); // push_api_->SetPushRtspURL(push_handle, "rtsp://player.daniulive.com:554/liverelay111.sdp"); // push_api_->StartPushRtsp(push_handle, 0); // // test push rtsp-- is_pushing_ = true; return true; }

上图:

这个时候,输入转发设置的Key(支持aes 128, aes 192, aes 256加密,即将发布SM4加密),方可正常播放音视频数据。

此种方案的优势在于基于AES音视频逐帧数据加密音视频数据,第三方即便是破解了URL,也没法播放,通过抓包工具抓取到数据,也没法正常显示。

猜你喜欢

转载自www.cnblogs.com/daniulivesdk/p/10960823.html