Password Encryption And Decryption
Here is cod for encryption and Decryption of the password.
For Encryption
Private Shared KEY_64() As Byte = {42, 16, 93, 156, 78, 4, 218, 32}
Private Shared IV_64() As Byte = {55, 103, 246, 79, 36, 99, 167, 3}
public static string Encryption(string value)
{
if (value != "")
{
DESCryptoServiceProvider CryptoProvidor = new DESCryptoServiceProvider();
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, CryptoProvidor.CreateEncryptor(Key_64, Iv_64), CryptoStreamMode.Write);
StreamWriter sw = new StreamWriter(cs);
sw.Write(value);
sw.Flush();
cs.FlushFinalBlock();
ms.Flush();
return Convert.ToBase64String(ms.GetBuffer(), 0, Convert.ToInt32(ms.Length));
}
return string.Empty;
}
For Decryption
public static string Descryption(string value)
{
if (value != "")
{
DESCryptoServiceProvider CryptoProvidor = new DESCryptoServiceProvider();
Byte[] buf = Convert.FromBase64String(value);
MemoryStream ms = new MemoryStream(buf);
CryptoStream cs = new CryptoStream(ms, CryptoProvidor.CreateDecryptor(Key_64, Iv_64), CryptoStreamMode.Read);
StreamReader sr = new StreamReader(cs);
return sr.ReadToEnd();
}
return string.Empty;
}
How to Use
----------
-> When User enter their new password then you pass the string to "Encryption" method they take one argument as as string this way
string strencryptpwd = Encryption(yourpassword);
this is return encrypt string store this code in the database.
-> When you retire that password from the database then pass that encrypt string to "Descryption" method they accept encrypt string and return orignal value. This way
string strencryptpwd = Descryption(yourencryptstring);
what is Key_64 and Iv_64 ? and where u r filling them ?