public static string EncryptPassword(string Password) //UTF8 Format Encryption
{
string strEncrKey = "&%#@?,:*";
byte[] byKey = new byte[100];
byte[] IV = { 18, 52, 86, 120, 144, 171, 205, 239 };
try
{
//byKey = System.Text.Encoding.UTF8.GetBytes(Left(strEncrKey, 8));
byKey = System.Text.Encoding.UTF8.GetBytes(strEncrKey.Substring(0, 8));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray = Encoding.UTF8.GetBytes(Password);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(byKey, IV),
CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
return Convert.ToBase64String(ms.ToArray());
}
catch (Exception ex)
{
return "ConfigFile" + ex.Message;
}
}
public static string DecryptPassword(string Password) //UTF8 Format Decryption
{
string sDecrKey = "&%#@?,:*";
byte[] byKey = new byte[100];
byte[] IV = { 18, 52, 86, 120, 144, 171, 205, 239 };
byte[] inputByteArray = new byte[Password.Length];
try
{
byKey = System.Text.Encoding.UTF8.GetBytes(sDecrKey.Substring(0, 8));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
inputByteArray = Convert.FromBase64String(Password);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(byKey, 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 ex)
{
return "ConfigFile" + ex.Message;
}
}
Friday, June 5, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment