HI,
Here is a solution that you can use for the decription of password.
/// <summary>
/// This function is used for the decription of the password.
/// </summary>
/// <param name="stringToDecrypt"></param>
/// <returns></returns>
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;
}
}
For encription use the following:
/// <summary>
/// This function is used for the encription of the password.
/// </summary>
/// <param name="stringToEncrypt">String to encript</param>
/// <returns></returns>
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;
}
}
Thanks