IT运维管理,创造商业价值!
中国IT运维网首页 | 资讯中心 | 运维管理 | 信息安全 | CIO视界 | 云计算 | 最佳案例 | 运维资源 | 专题策划 | 知识库 | 论坛

Web程序与应用程序通用Md5

2005年12月07日
/
<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&lt;data.Length ;i++)
{
sb[i*2]=HEX_TABLE[data[i]&gt;&gt;4];
sb[i*2+1]=HEX_TABLE[data[i] &amp; 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>
发表评论请到:http://bbs.cnitom.com

相关阅读

图文热点

如何在交付周期中保护Web应用程序安全性
如何在交付周期中保护Web应用程序安全性Web应用程序是当今多数企业应用的前沿阵地。Web应用程序在一个复杂的混合性架构中...
微软加强Hotmail安全 加密通信介入
微软加强Hotmail安全 加密通信介入微软周一表示,他们计划在Hotmail中部署增强后的安全功能,确保攻击者无法实现非...

本类热点