public static Decrypt ( byte cipherText, System.Security.Cryptography.CngKey key, CngAlgorithm hash ) : byte[] | ||
cipherText | byte | |
key | System.Security.Cryptography.CngKey | |
hash | CngAlgorithm | |
return | byte[] |
public byte[] Unwrap(byte[] encryptedCek, object key, int cekSizeBits, IDictionary <string, object> header) { var privateKey = Ensure.Type <RSACryptoServiceProvider>(key, "RsaKeyManagement alg expects key to be of RSACryptoServiceProvider type."); return(useSha256 ? RsaOaep.Decrypt(encryptedCek, RsaKey.New(privateKey.ExportParameters(true)), CngAlgorithm.Sha256) : privateKey.Decrypt(encryptedCek, useRsaOaepPadding)); }
public byte[] Unwrap(byte[] encryptedCek, object key, int cekSizeBits, IDictionary <string, object> header) { #if NET40 if (key is CngKey cngKey) { return(RsaOaep.Decrypt(encryptedCek, cngKey, CngAlgorithm.Sha256)); } else if (key is RSACryptoServiceProvider rsaKey) { //This is for backward compatibility only with 2.x //To be removed in 3.x var privateKey = RsaKey.New(rsaKey.ExportParameters(true)); return(RsaOaep.Decrypt(encryptedCek, privateKey, CngAlgorithm.Sha256)); } throw new ArgumentException("RsaKeyManagement algorithm expects key to be of CngKey type."); #elif NET461 || NET472 if (key is CngKey cngKey) { return(RsaOaep.Decrypt(encryptedCek, cngKey, CngAlgorithm.Sha256)); } else if (key is RSACryptoServiceProvider rsaKey) { //This is for backward compatibility only with 2.x //To be removed in 3.x var privateKey = RsaKey.New(rsaKey.ExportParameters(true)); return(RsaOaep.Decrypt(encryptedCek, privateKey, CngAlgorithm.Sha256)); } else if (key is RSA rsa) { return(rsa.Decrypt(encryptedCek, RSAEncryptionPadding.OaepSHA256)); } else if (key is Jwk jwk) { if (jwk.Kty == Jwk.KeyTypes.RSA) { return(jwk.RsaKey().Decrypt(encryptedCek, RSAEncryptionPadding.OaepSHA256)); } } throw new ArgumentException("RsaKeyManagement algorithm expects key to be of CngKey, RSACryptoServiceProvider, RSA types or Jwk type with kty='rsa'."); #elif NETSTANDARD if (key is RSA rsa) { return(rsa.Decrypt(encryptedCek, RSAEncryptionPadding.OaepSHA256)); } else if (key is Jwk jwk) { if (jwk.Kty == Jwk.KeyTypes.RSA) { return(jwk.RsaKey().Decrypt(encryptedCek, RSAEncryptionPadding.OaepSHA256)); } } throw new ArgumentException("RsaKeyManagement algorithm expects key to be of RSA type or Jwk type with kty='rsa'."); #endif }
public byte[] Unwrap(byte[] encryptedCek, object key, int cekSizeBits, IDictionary <string, object> header) { RSACryptoServiceProvider rSACryptoServiceProvider = Ensure.Type <RSACryptoServiceProvider>(key, "RsaKeyManagement alg expects key to be of RSACryptoServiceProvider type.", new object[0]); if (!this.useSha256) { return(rSACryptoServiceProvider.Decrypt(encryptedCek, this.useRsaOaepPadding)); } return(RsaOaep.Decrypt(encryptedCek, RsaKey.New(rSACryptoServiceProvider.ExportParameters(true)), CngAlgorithm.Sha256)); }
public byte[] Unwrap(byte[] encryptedCek, object key, int cekSizeBits, IDictionary <string, object> header) { #if NET40 var privateKey = Ensure.Type <CngKey>(key, "RsaKeyManagement alg expects key to be of RSACryptoServiceProvider type."); return(RsaOaep.Decrypt(encryptedCek, privateKey, CngAlgorithm.Sha256)); #elif NETSTANDARD1_4 var privateKey = Ensure.Type <RSA>(key, "RsaKeyManagement alg expects key to be of RSA type."); return(privateKey.Decrypt(encryptedCek, RSAEncryptionPadding.OaepSHA256)); #endif }
public byte[] Unwrap(byte[] encryptedCek, object key, int cekSizeBits, IDictionary <string, object> header) { #if NET40 if (key is RSACryptoServiceProvider) { //This is for backward compatibility only with 2.x //To be removed in 3.x var privateKey = RsaKey.New(((RSACryptoServiceProvider)key).ExportParameters(true)); return(RsaOaep.Decrypt(encryptedCek, privateKey, CngAlgorithm.Sha256)); } if (key is CngKey) { var privateKey = (CngKey)key; return(RsaOaep.Decrypt(encryptedCek, privateKey, CngAlgorithm.Sha256)); } throw new ArgumentException("RsaKeyManagement algorithm expects key to be of CngKey type."); #elif NET461 if (key is CngKey) { var privateKey = (CngKey)key; return(RsaOaep.Decrypt(encryptedCek, privateKey, CngAlgorithm.Sha256)); } if (key is RSACryptoServiceProvider) { //This is for backward compatibility only with 2.x //To be removed in 3.x var privateKey = RsaKey.New(((RSACryptoServiceProvider)key).ExportParameters(true)); return(RsaOaep.Decrypt(encryptedCek, privateKey, CngAlgorithm.Sha256)); } if (key is RSA) { var privateKey = (RSA)key; return(privateKey.Decrypt(encryptedCek, RSAEncryptionPadding.OaepSHA256)); } throw new ArgumentException("RsaKeyManagement algorithm expects key to be of either CngKey or RSA types."); #elif NETSTANDARD var privateKey = Ensure.Type <RSA>(key, "RsaKeyManagement algorithm expects key to be of RSA type."); return(privateKey.Decrypt(encryptedCek, RSAEncryptionPadding.OaepSHA256)); #endif }
public byte[] Unwrap(byte[] encryptedCek, object key, int cekSizeBits, IDictionary <string, object> header) { #if NET40 var privateKey = Ensure.Type <RSACryptoServiceProvider>(key, "RsaKeyManagement alg expects key to be of RSACryptoServiceProvider type."); return(useSha256 ? RsaOaep.Decrypt(encryptedCek, RsaKey.New(privateKey.ExportParameters(true)), CngAlgorithm.Sha256) : privateKey.Decrypt(encryptedCek, useRsaOaepPadding)); #elif NETSTANDARD1_4 var privateKey = Ensure.Type <RSA>(key, "RsaKeyManagement alg expects key to be of RSA type."); var padding = useSha256 ? RSAEncryptionPadding.OaepSHA256 : useRsaOaepPadding ? RSAEncryptionPadding.OaepSHA1 : RSAEncryptionPadding.Pkcs1; return(privateKey.Decrypt(encryptedCek, padding)); #endif }