AES-256-CBC decryption using secret key,ivector,ciphertext in c# | How to implement a C# AES-256 decrypt function?


A sample C# class to decrypt strings using the cipher AES-256-CBC

Add the necessary using directive to your code file to include the required classes:

using System;
using System.Security.Cryptography;
using System.Text;

AES Signature Decrypt using a key, IVector, CiperText
AES SignatureEncryptedValue Decrypt using symatric key,ivector,SignatureEncryptedValue

        byte[] key = Encoding.UTF8.GetBytes(SecretKey); // Replace with your key // input
        byte[] iv = Encoding.UTF8.GetBytes(IVECTOR); // Replace with your IV // input
        byte[] SignatureencryptedBytes = Convert.FromBase64String(ciphertext.ToString()); // Replace with your ciphertext // input

        string decryptedText = DecryptAES(SignatureencryptedBytes, key, iv);
        FinalPayentResponseDecrpt = decryptedText;
public static string DecryptAES(byte[] cipherText, byte[] key, byte[] iv)
        {
            using (AesCryptoServiceProvider aesAlg = new AesCryptoServiceProvider())
            {
                aesAlg.Key = key;
                aesAlg.IV = iv;

                // Create a decryptor to perform the stream transform
                ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);

                using (MemoryStream msDecrypt = new MemoryStream(cipherText))
                using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
                using (StreamReader srDecrypt = new StreamReader(csDecrypt))
                {
                    // Read the decrypted bytes from the decrypting stream
                    return srDecrypt.ReadToEnd();
                }
            }
        }
Response like : *****

Post a Comment

0 Comments