using System.Security.Cryptography;
public static void Main()
Console.WriteLine("ENcrypted: " + Encrypt("mk00848558@techmahindra.com#d7406010-0461-472f-8f8a-733e0fa5a3c9"));
private const string initVector = "h7g3e4m3t5st5zjw";
private const int keysize = 256;
public static string Decrypt(string str)
if (string.IsNullOrEmpty(str))
str = str.Replace(" ", "+");
string DecryptKey = "2013;[pnuLIT)WebCodeExpert";
byte[] IV = { 18, 52, 86, 120, 144, 171, 205, 239 };
byte[] inputByteArray = new byte[str.Length];
byKey = System.Text.Encoding.UTF8.GetBytes(DecryptKey.Substring(0, 8));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
inputByteArray = Convert.FromBase64String(str.Replace(" ", "+"));
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(byKey, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
System.Text.Encoding encoding = System.Text.Encoding.UTF8;
return encoding.GetString(ms.ToArray());
public static string Encrypt(string str)
if (string.IsNullOrEmpty(str))
string EncrptKey = "2013;[pnuLIT)WebCodeExpert";
byte[] IV = { 18, 52, 86, 120, 144, 171, 205, 239 };
byKey = System.Text.Encoding.UTF8.GetBytes(EncrptKey.Substring(0, 8));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray = Encoding.UTF8.GetBytes(str);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(byKey, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
return Convert.ToBase64String(ms.ToArray());