/// <summary> /// Encrypts the content key to certificate. /// </summary> /// <param name="cert">The cert.</param> /// <param name="contentKey">The content key.</param> /// <returns>The encrypted content key.</returns> public static byte[] EncryptContentKeyToCertificate(X509Certificate2 cert, byte[] contentKey) { byte[] returnValue = null; if (cert == null) { throw new ArgumentNullException("cert"); } if (contentKey == null) { throw new ArgumentNullException("contentKey"); } if (contentKey.Length != EncryptionUtils.KeySizeInBytesForAes128) { throw new ArgumentOutOfRangeException("contentKey", "Common Encryption content keys are 128-bits (16 bytes) in length."); } using (AesCryptoServiceProvider key = new AesCryptoServiceProvider()) { key.Key = contentKey; returnValue = EncryptionUtils.EncryptSymmetricKey(cert, key); } return(returnValue); }
/// <summary> /// Encrypts the content key to certificate. /// </summary> /// <param name="certToUse">The cert to use.</param> /// <returns>The encrypted content key.</returns> public byte[] EncryptContentKeyToCertificate(X509Certificate2 certToUse) { return(EncryptionUtils.EncryptSymmetricKey(certToUse, this._key)); }