asp.net MD5的几种加密函数写法(c#)
[ 2006-04-09 01:41:00 | 作者: admin ]
利用下面的方法,可直接输入数据,反回md5加密后的代码
版本1:
string MD5_1(string strText)
{
MD5CryptoServiceProvider csp = new MD5CryptoServiceProvider();
byte[] bytes = System.Text.Encoding.Default.GetBytes(strText);
byte[] hashedBytes = csp.ComputeHash(bytes, 0, bytes.Length);
return BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
}
版本2:
string MD5_2(string strText)
{
MD5CryptoServiceProvider x = new MD5CryptoServiceProvider();
byte[] bs = System.Text.Encoding.Default.GetBytes(strText);
bs = x.ComputeHash(bs);
System.Text.StringBuilder s = new System.Text.StringBuilder();
foreach (byte b in bs)
{
s.Append(b.ToString("x2").ToLower());
}
return s.ToString();
}
版本3:
string MD5(string Sourcein)
{
MD5CryptoServiceProvider MD5CSP = new MD5CryptoServiceProvider();
byte[] MD5Source = System.Text.Encoding.UTF8.GetBytes(Sourcein);
byte[] MD5Out = MD5CSP.ComputeHash(MD5Source);
return Convert.ToBase64String(MD5Out);
}
评论Feed: http://blog.xg98.com/feed.asp?q=comment&id=421
版本1:
string MD5_1(string strText)
{
MD5CryptoServiceProvider csp = new MD5CryptoServiceProvider();
byte[] bytes = System.Text.Encoding.Default.GetBytes(strText);
byte[] hashedBytes = csp.ComputeHash(bytes, 0, bytes.Length);
return BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
}
版本2:
string MD5_2(string strText)
{
MD5CryptoServiceProvider x = new MD5CryptoServiceProvider();
byte[] bs = System.Text.Encoding.Default.GetBytes(strText);
bs = x.ComputeHash(bs);
System.Text.StringBuilder s = new System.Text.StringBuilder();
foreach (byte b in bs)
{
s.Append(b.ToString("x2").ToLower());
}
return s.ToString();
}
版本3:
string MD5(string Sourcein)
{
MD5CryptoServiceProvider MD5CSP = new MD5CryptoServiceProvider();
byte[] MD5Source = System.Text.Encoding.UTF8.GetBytes(Sourcein);
byte[] MD5Out = MD5CSP.ComputeHash(MD5Source);
return Convert.ToBase64String(MD5Out);
}
[最后修改由 admin, 于 2006-05-16 16:00:44]

这篇日志没有评论。
此日志不可发表评论。