using Microsoft.VisualBasic;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
using System.Web.Configuration;
private static byte[] m_Key = new byte[8];
private static byte[] m_IV = new byte[8];
public static void Main()
var plainPassword = DecryptData("key4intotheblue", "snW9MAvMKSVMe+JOklH7GQ==");
Console.WriteLine(string.Format("Password is: {0}", plainPassword));
public static string DecryptData(string strKey, string strData)
strResult = "Error. Failed to generate key for decryption";
DESCryptoServiceProvider descsp = new DESCryptoServiceProvider();
ICryptoTransform desDecrypt = descsp.CreateDecryptor(m_Key, m_IV);
MemoryStream mOut = new MemoryStream();
CryptoStream cs = new CryptoStream(mOut, desDecrypt, CryptoStreamMode.Write);
byte[] bPlain = new byte[strData.Length + 1];
bPlain = Convert.FromBase64CharArray(strData.ToCharArray(), 0, strData.Length);
strResult = "Error. Input Data is not base64 encoded.";
long lTotal = strData.Length;
while ((lTotal >= lRead))
cs.Write(bPlain, 0, System.Convert.ToInt32(bPlain.Length));
lRead = mOut.Length + System.Convert.ToInt64(Convert.ToInt32(((bPlain.Length / (double)descsp.BlockSize) * descsp.BlockSize)));
ASCIIEncoding aEnc = new ASCIIEncoding();
strResult = aEnc.GetString(mOut.GetBuffer(), 0, System.Convert.ToInt32(mOut.Length));
string strLen = strResult.Substring(0, 5);
int nLen = Convert.ToInt32(strLen);
strResult = strResult.Substring(5, nLen);
nReturn = System.Convert.ToInt32(mOut.Length);
strResult = "Error. Decryption Failed. Possibly due to incorrect Key or corrputed data";
private static bool InitKey(string strKey)
byte[] bp = new byte[strKey.Length + 1];
ASCIIEncoding aEnc = new ASCIIEncoding();
aEnc.GetBytes(strKey, 0, strKey.Length, bp, 0);
SHA1CryptoServiceProvider sha = new SHA1CryptoServiceProvider();
byte[] bpHash = sha.ComputeHash(bp);
for (i = 8; i <= 15; i++)