Decrypt DES - CSharp Security

CSharp examples for Security:MD5

Description

Decrypt DES

Demo Code


using System.Drawing.Imaging;
using System.Drawing;
using System.IO;/*from   ww  w  . j  a v  a2  s .  c  o  m*/
using System.Security.Cryptography;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;

public class Main{
        public static string DecryptDES(string decryptString, string decryptKey)
        {
            try
            {
                byte[] rgbKey = Encoding.UTF8.GetBytes(decryptKey);
                byte[] rgbIV = Keys;
                byte[] inputByteArray = Convert.FromBase64String(decryptString);
                DESCryptoServiceProvider DCSP = new DESCryptoServiceProvider();
                MemoryStream mStream = new MemoryStream();
                CryptoStream cStream = new CryptoStream(mStream, DCSP.CreateDecryptor(rgbKey, rgbIV), CryptoStreamMode.Write);
                cStream.Write(inputByteArray, 0, inputByteArray.Length);
                cStream.FlushFinalBlock();
                return Encoding.UTF8.GetString(mStream.ToArray());
            }
            catch
            {
                return decryptString;
            }
        }
}

Related Tutorials