DRM インポートの初期化の例
[このページに関連付けられている機能である Windows Media Format 11 SDK は、レガシ機能です。 これは、ソース リーダーとシンク ライターによって置き換えられます。 ソース リーダーとシンク ライターは、Windows 10とWindows 11用に最適化されています。 新しいコードでは、可能であれば、Windows Media Format 11 SDK ではなくソース リーダーとシンク ライターを使用することを強くお勧めします。 Microsoft は、従来の API を使用する既存のコードを、可能であれば新しい API を使用するように書き直すよう提案しています。]
次のコード例は、DRM インポート用に DRM ライター オブジェクトを初期化する方法を示しています。
HRESULT InitializeImport( IWMDRMWriter3 *pDRMWriter )
{
// Set this value to the desired number of bytes in an encrypted
// session key.
const int MODULUS_SIZE = 32;
HRESULT hr = S_OK;
WMDRM_IMPORT_INIT_STRUCT ImportInit;
BYTE *pbEncryptedSessionKey = NULL;
DWORD cbEncryptedSessionKey = 0;
WMDRM_IMPORT_SESSION_KEY *pSessionKey = NULL;
DWORD cbSessionKey = 0;
WMDRM_IMPORT_CONTENT_KEY *pContentKey = NULL;
DWORD cbContentKey = 0;
// Allocate memory for the encrypted session key.
pbEncryptedSessionKey = new BYTE[ MODULUS_SIZE ];
if( NULL == pbEncryptedSessionKey )
{
hr = E_OUTOFMEMORY;
goto EXIT;
}
cbEncryptedSessionKey = MODULUS_SIZE;
hr = CreateSessionKey( &pSessionKey, &cbSessionKey );
if( FAILED( hr ) ) goto EXIT;
if( cbSessionKey > MODULUS_SIZE )
if( FAILED( hr ) ) goto EXIT;
hr = CreateContentKey( &pContentKey, &cbContentKey );
if( FAILED( hr ) ) goto EXIT;
// TODO: Encrypt the content key with the session Key.
// TODO: Encrypt the session key with the machine certificate public key.
ImportInit.dwVersion = 0;
ImportInit.pbEncryptedSessionKeyMessage = pbEncryptedSessionKey;
ImportInit.cbEncryptedSessionKeyMessage = cbEncryptedSessionKey;
ImportInit.pbEncryptedKeyMessage = (BYTE*)pContentKey;
ImportInit.cbEncryptedKeyMessage = cbContentKey;
hr = pDRMWriter->SetProtectStreamSamples( &ImportInit );
if( FAILED( hr ) ) goto EXIT;
EXIT:
SAFE_ARRAY_DELETE( pContentKey );
SAFE_ARRAY_DELETE( pSessionKey );
return( hr );
}
関連トピック