using System.Security.Cryptography;
private static byte[] mabtyBufferOld;
private static TripleDESCryptoServiceProvider mobjDESOld;
private static byte[] mabtyBuffer;
private static AesCryptoServiceProvider mobjDES;
public const int KEY_SIZE = 16;
static SHA256CryptoServiceProvider sha256CryptoServiceProvider;
static byte[] key = new byte[KEY_SIZE];
static byte[] iv = new byte[KEY_SIZE];
public static void Main()
string current = "88OCejn6QH8=";
string dec = Program.Current(current);
Console.WriteLine("Val In Old \n" + dec);
string s = Program.Encrypt(dec);
Console.WriteLine("Val to replace with \n" + s);
string d = Program.Decrypt(s);
Console.WriteLine("Val decrpted \n" + d);
private static void Construct()
sha256CryptoServiceProvider = new SHA256CryptoServiceProvider();
strKey = string.Concat(strKey, "<well I'm hardly going to tell you my key...!>");
var hash = sha256CryptoServiceProvider.ComputeHash(Encoding.UTF8.GetBytes(strKey));
Buffer.BlockCopy(hash, 0, key, 0, KEY_SIZE);
Buffer.BlockCopy(hash, KEY_SIZE, iv, 0, KEY_SIZE);
private static void Deconstruct()
private static string Encrypt(string pstrText)
using (var cipher = new AesCryptoServiceProvider().CreateEncryptor(key, iv))
using (var output = new MemoryStream())
using (var cryptoStream = new CryptoStream(output, cipher, CryptoStreamMode.Write))
var inputBytes = Encoding.UTF8.GetBytes(pstrText);
cryptoStream.Write(inputBytes, 0, inputBytes.Length);
var bytes = output.ToArray();
return Convert.ToBase64String(bytes);
throw new Exception(ex.Message);
private static string Decrypt(string pstrText)
var encryptedBytes = Convert.FromBase64String(pstrText);
using (var cipher = new AesCryptoServiceProvider().CreateDecryptor(key, iv))
using (var source = new MemoryStream(encryptedBytes))
using (var output = new MemoryStream())
using (var cryptoStream = new CryptoStream(source, cipher, CryptoStreamMode.Read))
cryptoStream.CopyTo(output);
return Encoding.UTF8.GetString(output.ToArray());
throw new Exception(ex.Message);
private static string Current(string pstrText)
MD5CryptoServiceProvider hashmd5;
strKey = string.Concat(strKey, "<well I'm hardly going to tell you my key...!>");
hashmd5 = new MD5CryptoServiceProvider();
abytKeyHash = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(strKey));
mobjDESOld = new TripleDESCryptoServiceProvider();
mobjDESOld.Key = abytKeyHash;
mobjDESOld.Mode = CipherMode.ECB;
mabtyBufferOld = UTF8Encoding.UTF8.GetBytes(pstrText);
string Enc = Convert.ToBase64String(mobjDESOld.CreateEncryptor().TransformFinalBlock(mabtyBufferOld, 0, mabtyBufferOld.Length));
mabtyBufferOld = Convert.FromBase64String(pstrText);
string Dec = UTF8Encoding.UTF8.GetString(mobjDESOld.CreateDecryptor().TransformFinalBlock(mabtyBufferOld, 0, mabtyBufferOld.Length));