DRM 가져오기 초기화 예제
[이 페이지와 연결된 기능인 Windows Media Format 11 SDK는 레거시 기능입니다. 원본 판독기 및 싱크 작성기에 의해 대체되었습니다. 원본 판독기 및 싱크 작성기는 Windows 10 및 Windows 11 최적화되었습니다. 가능한 경우 새 코드에서 Windows Media Format 11 SDK 대신 소스 판독기 및 싱크 작성기를 사용하는 것이 좋습니다. 가능한 경우 레거시 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 );
}
관련 항목