C#中怎样实现MD5加密?MD5中加密算法16位加密算法与32位加密算法怎么实现?
1个回答
展开全部
调用这个类就行了
using System.Text;
using System.Security.Cryptography;
namespace class1
{
[System.Diagnostics.DebuggerStepThroughAttribute()]
public static class MD5Encode
{
//用md5 hash 字符串
public static string MD5Hash(string str)
{
ASCIIEncoding ASC = new ASCIIEncoding();
byte[] arrPwd = ASC.GetBytes(str);
MD5 md5 = new MD5CryptoServiceProvider();
byte[] arrHashPwd = md5.ComputeHash(arrPwd);
//转成字符串,表示十六进制值
string sHashPwd = "";
foreach (byte b in arrHashPwd)
{
if (b < 16)
sHashPwd = sHashPwd + "0" + b.ToString("x");
else
sHashPwd = sHashPwd + b.ToString("x");
}
return sHashPwd;
}
}
}
using System.Text;
using System.Security.Cryptography;
namespace class1
{
[System.Diagnostics.DebuggerStepThroughAttribute()]
public static class MD5Encode
{
//用md5 hash 字符串
public static string MD5Hash(string str)
{
ASCIIEncoding ASC = new ASCIIEncoding();
byte[] arrPwd = ASC.GetBytes(str);
MD5 md5 = new MD5CryptoServiceProvider();
byte[] arrHashPwd = md5.ComputeHash(arrPwd);
//转成字符串,表示十六进制值
string sHashPwd = "";
foreach (byte b in arrHashPwd)
{
if (b < 16)
sHashPwd = sHashPwd + "0" + b.ToString("x");
else
sHashPwd = sHashPwd + b.ToString("x");
}
return sHashPwd;
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询