扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
<P><b>Web中:</b></P>
<P>using System.Web.Security;</P>
<P>public string md5(string baseString)
{
return FormsAuthentication.HashPasswordForStoringInConfigFile(baseString,"MD5");
}</P>
<P><b>应用程序中:</b></P>
<P>using System.Security.Cryptography; </P>
<P>public static string GetMD5(Stream stream)
{
const string HEX_TABLE = "0123456789ABCDEF";
MD5 md5 = new MD5CryptoServiceProvider();
//Calculate MD5 Checksum
byte[]data = md5.ComputeHash(stream);
//convert to string
StringBuilder sb=new StringBuilder();
sb.Length =data.Length *2;
for(int i=0;i<data.Length ;i++)
{
sb[i*2]=HEX_TABLE[data[i]>>4];
sb[i*2+1]=HEX_TABLE[data[i] & 0xF];
}
return sb.ToString();
}
public static string GetMD5(string s)
{
byte[] data=ASCIIEncoding.ASCII.GetBytes(s);
MemoryStream stream=new MemoryStream(data);
//stream.Write(data,0,data.Length);
return GetMD5(stream);
}
</P>
濡傛灉鎮ㄩ潪甯歌揩鍒囩殑鎯充簡瑙T棰嗗煙鏈€鏂颁骇鍝佷笌鎶€鏈俊鎭紝閭d箞璁㈤槄鑷抽《缃戞妧鏈偖浠跺皢鏄偍鐨勬渶浣抽€斿緞涔嬩竴銆�