/// <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> /// Gets the checksum. /// </summary> /// <returns>The checksum.</returns> public string GetChecksum() { return(EncryptionUtils.CalculateChecksum(this._key.Key, this.KeyIdentifier)); }