HI,
You can use the encription and decription of any kind of strings using the following two methods.
public static string Decrypt(string stringToDecrypt)
{
MemoryStream ms = null;
byte[] inputByteArray = new byte[stringToDecrypt.Length + 1];
try
{
byte[] key = { };
string sEncryptionKey = "!#$a54?3";
byte[] IV = { 18, 52, 86, 120, 144, 171, 205, 239 };
key = Encoding.UTF8.GetBytes(sEncryptionKey);
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
inputByteArray = Convert.FromBase64String(stringToDecrypt);
ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(key, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
System.Text.Encoding encoding = System.Text.Encoding.UTF8;
return encoding.GetString(ms.ToArray());
}
catch (Exception e)
{
return e.Message;
}
finally
{
ms = null;
}
}
public static string Encrypt(string stringToEncrypt)
{
MemoryStream ms = null;
try
{
byte[] key = { };
string sEncryptionKey = "!#$a54?3";
byte[] IV = { 18, 52, 86, 120, 144, 171, 205, 239 };
key = Encoding.UTF8.GetBytes(sEncryptionKey);
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray = Encoding.UTF8.GetBytes(stringToEncrypt);
ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(key, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
return Convert.ToBase64String(ms.ToArray());
}
catch (Exception e)
{
return e.Message;
}
finally
{
ms = null;
}
}
Use these two method in your encription and decription of data.
Thanks