/// <summary> /// Creates an envelope encryption content key. /// </summary> /// <param name="keyId">The key id.</param> /// <param name="contentKey">The content key data.</param> /// <param name="name">The name.</param> /// <param name="cert">The cert.</param> /// <returns>The content key.</returns> internal static ContentKeyData InitializeEnvelopeContentKey(Guid keyId, byte[] contentKey, string name, X509Certificate2 cert) { if (cert == null) { throw new ArgumentNullException("cert"); } if (contentKey == null) { throw new ArgumentNullException("contentKey"); } if (contentKey.Length != EncryptionUtils.KeySizeInBytesForAes128) { throw new ArgumentOutOfRangeException("contentKey", "Envelope Encryption content keys are 128-bits (16 bytes) in length."); } byte[] encryptedContentKey = EncryptionUtils.EncryptSymmetricKeyData(cert, contentKey); ContentKeyData contentKeyData = new ContentKeyData { Id = EncryptionUtils.GetKeyIdentifierAsString(keyId), EncryptedContentKey = Convert.ToBase64String(encryptedContentKey), ContentKeyType = (int)ContentKeyType.EnvelopeEncryption, ProtectionKeyId = cert.Thumbprint, ProtectionKeyType = (int)ProtectionKeyType.X509CertificateThumbprint, Name = name, Checksum = EncryptionUtils.CalculateChecksum(contentKey, keyId) }; return(contentKeyData); }
/// <summary> /// Creates the common content key. /// </summary> /// <param name="keyId">The key id.</param> /// <param name="contentKey">The content key data.</param> /// <param name="name">The name.</param> /// <param name="cert">The cert.</param> /// <returns>The content key.</returns> internal static ContentKeyData CreateCommonContentKey(Guid keyId, byte[] contentKey, string name, X509Certificate2 cert) { byte[] encryptedContentKey = CommonEncryption.EncryptContentKeyToCertificate(cert, contentKey); ContentKeyData contentKeyData = new ContentKeyData { Id = EncryptionUtils.GetKeyIdentifierAsString(keyId), EncryptedContentKey = Convert.ToBase64String(encryptedContentKey), ContentKeyType = (int)ContentKeyType.CommonEncryption, ProtectionKeyId = cert.Thumbprint, ProtectionKeyType = (int)ProtectionKeyType.X509CertificateThumbprint, Name = name, Checksum = EncryptionUtils.CalculateChecksum(contentKey, keyId) }; return(contentKeyData); }
/// <summary> /// Creates FairPlay Pfx Password. /// </summary> /// <param name="keyId">The key id.</param> /// <param name="contentKey">The content key data.</param> /// <param name="name">The name.</param> /// <param name="cert">The cert.</param> /// <returns>The content key.</returns> internal static ContentKeyData InitializeFairPlayPfxPassword(Guid keyId, byte[] contentKey, string name, X509Certificate2 cert) { RSACryptoServiceProvider rsaPublicKey = cert.PublicKey.Key as RSACryptoServiceProvider; RSAOAEPKeyExchangeFormatter keyFormatter = new RSAOAEPKeyExchangeFormatter(rsaPublicKey); byte[] encryptedContentKey = keyFormatter.CreateKeyExchange(contentKey); ContentKeyData contentKeyData = new ContentKeyData { Id = EncryptionUtils.GetKeyIdentifierAsString(keyId), EncryptedContentKey = Convert.ToBase64String(encryptedContentKey), ContentKeyType = (int)ContentKeyType.FairPlayPfxPassword, ProtectionKeyId = cert.Thumbprint, ProtectionKeyType = (int)ProtectionKeyType.X509CertificateThumbprint, Name = name, }; return(contentKeyData); }
/// <summary> /// Gets the key identifier as string. /// </summary> /// <returns>The key ID.</returns> public string GetKeyIdentifierAsString() { return(EncryptionUtils.GetKeyIdentifierAsString(this.KeyIdentifier)); }