媒体示例加密示例
[与此页面关联的功能 Windows Media Format 11 SDK 是旧版功能。 它已被源读取器和接收器编写器取代。 源读取器和接收器编写器已针对Windows 10和Windows 11进行了优化。 Microsoft 强烈建议新代码尽可能使用源读取器和接收器编写器,而不是 Windows Media Format 11 SDK。 如果可能,Microsoft 建议重写使用旧 API 的现有代码以使用新 API。]
以下不完整的示例演示如何使用 DRM 加密加密媒体示例。 由于空间限制,将 RC4 加密算法排除在示例中。
QWORD GetNextSalt(QWORD qwSalt)
{
return InterlockedIncrement64( (volatile LONGLONG*)&qwSalt );
}
HRESULT EncryptSample( INSSBuffer *pSample )
{
HRESULT hr = S_OK;
INSSBuffer3 *pNSSBuffer3 = NULL;
QWORD qwSalt = 0;
BYTE *pbData = NULL;
DWORD cbData = 0;
hr = pSample->QueryInterface( IID_INSSBuffer3, (void**)&pNSSBuffer3 );
if( FAILED( hr ) ) goto EXIT;
hr = pSample->GetBufferAndLength( &pbData, &cbData );
if( FAILED( hr ) ) goto EXIT;
qwSalt = GetNextSalt(qwSalt);
// TODO: Encrypt the sample by concatenating the initialization vector
// and using RC4 encryption.
hr = pNSSBuffer3->SetProperty(
WM_SampleExtensionGUID_SampleProtectionSalt,
&qwSalt, sizeof( qwSalt ) );
if( FAILED( hr ) ) goto EXIT;
EXIT:
SAFE_RELEASE( pNSSBuffer3 );
return hr;
}
相关主题