public static string MD5(string text)
{
MD5 md5 = new MD5CryptoServiceProvider();
byte[] inputText = Encoding.Default.GetBytes(text);
{
MD5 md5 = new MD5CryptoServiceProvider();
byte[] inputText = Encoding.Default.GetBytes(text);
byte[] buffer = md5.ComputeHash(inputText);
md5.Clear();
md5.Clear();
string str = string.Empty;
for (int i = 0; i < buffer.Length; i++)
{
str += buffer[i].ToString("x").PadLeft(2, '0');
}
return str;
}
for (int i = 0; i < buffer.Length; i++)
{
str += buffer[i].ToString("x").PadLeft(2, '0');
}
return str;
}
//public static string Encrypt(string text)
//{
// return Encrypt(text, "ghiegcge");
//}
//public static string Encrypt(string text, string sKey)
//{
// DESCryptoServiceProvider des = new DESCryptoServiceProvider();
// byte[] inpuText = Encoding.Default.GetBytes(text);
//{
// return Encrypt(text, "ghiegcge");
//}
//public static string Encrypt(string text, string sKey)
//{
// DESCryptoServiceProvider des = new DESCryptoServiceProvider();
// byte[] inpuText = Encoding.Default.GetBytes(text);
// des.IV = Encoding.Default.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile("sKey", "md5").Substring(0, 8));
// des.Key = Encoding.Default.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile("sKey", "md5").Substring(0, 8));
// des.Key = Encoding.Default.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile("sKey", "md5").Substring(0, 8));
// MemoryStream ms = new MemoryStream();
// CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
// cs.Write(inpuText, 0, inpuText.Length);
// cs.FlushFinalBlock();
// StringBuilder sb = new StringBuilder();
// foreach (byte b in ms.ToArray())
// {
// sb.AppendFormat("{0:x2}", b);
// }
// return sb.ToString();
//}
// CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
// cs.Write(inpuText, 0, inpuText.Length);
// cs.FlushFinalBlock();
// StringBuilder sb = new StringBuilder();
// foreach (byte b in ms.ToArray())
// {
// sb.AppendFormat("{0:x2}", b);
// }
// return sb.ToString();
//}
//public static string Decrypt(string text)
//{
// return Decrypt(text, "ghiegcge");
//}
//{
// return Decrypt(text, "ghiegcge");
//}
//public static string Decrypt(string text, string sKey)
//{
// DESCryptoServiceProvider des = new DESCryptoServiceProvider();
//{
// DESCryptoServiceProvider des = new DESCryptoServiceProvider();
// byte[] inputText = new byte[text.Length / 2];
// int i, x;
// for (x = 0; x < text.Length / 2; x++)
// {
// i = Convert.ToInt32(text.Substring(x * 2, 2), 16);
// inputText[x] = (byte)i;
// }
// des.IV = Encoding.Default.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile("sKey", "md5").Substring(0, 8));
// des.Key = Encoding.Default.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile("sKey", "md5").Substring(0, 8));
// int i, x;
// for (x = 0; x < text.Length / 2; x++)
// {
// i = Convert.ToInt32(text.Substring(x * 2, 2), 16);
// inputText[x] = (byte)i;
// }
// des.IV = Encoding.Default.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile("sKey", "md5").Substring(0, 8));
// des.Key = Encoding.Default.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile("sKey", "md5").Substring(0, 8));
// MemoryStream ms = new MemoryStream();
// CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
// cs.Write(inputText, 0, inputText.Length);
// cs.FlushFinalBlock();
// cs.FlushFinalBlock();
// return Encoding.Default.GetString(ms.ToArray());
//}