基於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,也沒法播放,通過抓包工具抓取到數據,也沒法正常顯示。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM