public string Md5Encrypt(string pToEncrypt)
{
using (DESCryptoServiceProvider des = new DESCryptoServiceProvider())
{
string sKey = "is me";
byte[] inputByteArray = Encoding.UTF8.GetBytes(pToEncrypt);
des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
using (CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write))
{
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
cs.Close();
}
string str = Convert.ToBase64String(ms.ToArray());
ms.Close();
return str;
}
{
using (DESCryptoServiceProvider des = new DESCryptoServiceProvider())
{
string sKey = "is me";
byte[] inputByteArray = Encoding.UTF8.GetBytes(pToEncrypt);
des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
using (CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write))
{
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
cs.Close();
}
string str = Convert.ToBase64String(ms.ToArray());
ms.Close();
return str;
}
}
这样写一个函数就实现md5加密了
本文介绍了一个简单的MD5加密函数实现方法,通过使用.NET Framework提供的DESCryptoServiceProvider类完成字符串加密过程,并将加密后的结果转换为Base64字符串形式。

2787

被折叠的 条评论
为什么被折叠?



