/// <summary> /// Decrypt raw data, generally used for decrypting symmetric key material /// </summary> /// <param name="rgb">encrypted data</param> /// <param name="fOAEP">true to use OAEP padding (PKCS #1 v2), false to use PKCS #1 type 2 padding</param> /// <returns>decrypted data</returns> public byte[] Decrypt(byte[] rgb, bool fOAEP) { ArgumentNullException.ThrowIfNull(rgb); // Save the KeySize value to a local because it has non-trivial cost. int keySize = KeySize; // size check -- must be exactly the modulus size if (rgb.Length != (keySize / 8)) { throw new CryptographicException(SR.Cryptography_RSA_DecryptWrongSize); } byte[] decryptedKey; CapiHelper.DecryptKey(SafeKeyHandle, rgb, rgb.Length, fOAEP, out decryptedKey); return(decryptedKey); }
/// <summary> /// Decrypt raw data, generally used for decrypting symmetric key material /// </summary> /// <param name="rgb">encrypted data</param> /// <param name="fOAEP">true to use OAEP padding (PKCS #1 v2), false to use PKCS #1 type 2 padding</param> /// <returns>decrypted data</returns> public byte[] Decrypt(byte[] rgb, bool fOAEP) { if (rgb == null) { throw new ArgumentNullException("rgb"); } GetKeyPair(); // size check -- must be at most the modulus size if (rgb.Length > (KeySize / 8)) { throw new CryptographicException(SR.Format(SR.Cryptography_Padding_DecDataTooBig, Convert.ToString(KeySize / 8))); } byte[] decryptedKey = null; CapiHelper.DecryptKey(_safeKeyHandle, rgb, rgb.Length, fOAEP, out decryptedKey); return(decryptedKey); }
/// <summary> /// Decrypt raw data, generally used for decrypting symmetric key material /// </summary> /// <param name="rgb">encrypted data</param> /// <param name="fOAEP">true to use OAEP padding (PKCS #1 v2), false to use PKCS #1 type 2 padding</param> /// <returns>decrypted data</returns> public byte[] Decrypt(byte[] rgb, bool fOAEP) { if (rgb == null) { throw new ArgumentNullException(nameof(rgb)); } // Save the KeySize value to a local because it has non-trivial cost. int keySize = KeySize; // size check -- must be at most the modulus size if (rgb.Length > (keySize / 8)) { throw new CryptographicException(SR.Format(SR.Cryptography_Padding_DecDataTooBig, Convert.ToString(keySize / 8))); } byte[] decryptedKey; CapiHelper.DecryptKey(SafeKeyHandle, rgb, rgb.Length, fOAEP, out decryptedKey); return(decryptedKey); }