internal static extern uint NCryptEncrypt(SafeNCryptKeyHandle hKey, byte[] pbInput, int cbInput, ref BCrypt.BCRYPT_OAEP_PADDING_INFO pvPadding, byte[] pbOutput, uint cbOutput, out uint pcbResult, uint dwFlags);
public static byte[] Decrypt(byte[] cipherText, CngKey key, CngAlgorithm hash) { var paddingInfo = new BCrypt.BCRYPT_OAEP_PADDING_INFO(hash.Algorithm); uint plainTextByteSize; uint status = NCrypt.NCryptDecrypt(key.Handle, cipherText, cipherText.Length, ref paddingInfo, null, 0, out plainTextByteSize, BCrypt.BCRYPT_PAD_OAEP); if (status != BCrypt.ERROR_SUCCESS) { throw new CryptographicException(string.Format("NCrypt.Decrypt() (plaintext buffer size) failed with status code:{0}", status)); } var plainText = new byte[plainTextByteSize]; status = NCrypt.NCryptDecrypt(key.Handle, cipherText, cipherText.Length, ref paddingInfo, plainText, plainTextByteSize, out plainTextByteSize, BCrypt.BCRYPT_PAD_OAEP); if (status != BCrypt.ERROR_SUCCESS) { throw new CryptographicException(string.Format("NCrypt.Decrypt() failed with status code:{0}", status)); } return(plainText); }