Decrypts a Rijndael encrypted string - CSharp System.Security.Cryptography

CSharp examples for System.Security.Cryptography:Encrypt Decrypt

Description

Decrypts a Rijndael encrypted string

Demo Code


using System.Text;
using System.Security.Cryptography;
using System;/*from www. j a v  a2s . c  o m*/

public class Main{
        /// <summary>
      ///     Decrypts a Rijndael encrypted string
      /// </summary>
      /// <returns>Decrypted string</returns>
      public static string Decrypt(string encryptedText)
      {
         var rijndael = new RijndaelManaged();
         rijndael.Key = Convert.FromBase64String(key);
         rijndael.IV = Convert.FromBase64String(IV);

         byte[] buffer = Convert.FromBase64String(encryptedText);

         return Encoding.UTF8.GetString(rijndael.CreateDecryptor().TransformFinalBlock(buffer, 0, buffer.Length));
      }
}

Related Tutorials