public void EncryptContentKeyToCertRoundTripTest() { var cert = new X509Certificate2("UnitTest.pfx"); var dataContextMock = new Mock <IMediaDataServiceContext>(); string testKey = "1234567890123456"; var fakeResponse = new string[] { Convert.ToBase64String(new System.Text.UTF8Encoding().GetBytes(testKey)) }; dataContextMock.Setup((ctxt) => ctxt .Execute <string>(It.IsAny <Uri>())) .Returns(() => { return(fakeResponse); }); _mediaContext.MediaServicesClassFactory = new TestMediaServicesClassFactory(dataContextMock.Object); var contentKey = new ContentKeyData { Name = "testData", Id = "id" }; contentKey.SetMediaContext(_mediaContext); byte[] encryptedKeyValue = contentKey.GetEncryptedKeyValue(cert); byte[] encryptedContentKey = CommonEncryption.EncryptContentKeyToCertificate(cert, encryptedKeyValue); byte[] decryptedContentKey = EncryptionUtils.DecryptSymmetricKey(cert, encryptedContentKey); Assert.IsTrue(encryptedKeyValue.SequenceEqual(decryptedContentKey)); }
//This API works the same as AESContentKey constructor in PlayReady Server SDK public static string GetPlayReadyContentKeyFromKeyIdKeySeed(string keyIdString, string keySeedB64) { Guid keyId = new Guid(keyIdString); byte[] keySeed = Convert.FromBase64String(keySeedB64); byte[] contentKey = CommonEncryption.GeneratePlayReadyContentKey(keySeed, keyId); string contentKeyB64 = Convert.ToBase64String(contentKey); return(contentKeyB64); }
public void PlayReadyContentKeyGenerationKnownGoodTest() { string _keySeed = "XVBovsmzhP9gRIZxWfFta3VVRPzVEWmJsazEJ46I"; string _knownGoodGuid = "339C45B5-FB6D-4BD9-994C-EABD9D41C95B"; string _wellKnownKeyString = "pTfNwMplhBQG1SXnvyLXVA=="; byte[] keySeedInBinary = Convert.FromBase64String(_keySeed); Guid wellKnownGuid = new Guid(_knownGoodGuid); byte[] generatedKey = CommonEncryption.GeneratePlayReadyContentKey(keySeedInBinary, wellKnownGuid); string generatedKeyAsString = Convert.ToBase64String(generatedKey); Assert.AreEqual <string>(_wellKnownKeyString, generatedKeyAsString); }