初级:.net框架下的MD5 :: 心随风起
来源: BlogBus 原始链接: http://mjm.blogbus.com:80/logs/2005/03/1067604.html 存档链接: https://web.archive.org/web/20060217052254id_/http://mjm.blogbus.com:80/logs/2005/03/1067604.html
心随风起 学习ASP.NET中的心得,与收集的一些资料 <<<生成随机字符串 | 返回首页 | 轮换广告>>> 初级:.net框架下的MD5 近日发现有程序员在.NET项目中自己编写MD5算法实现,为避免不必要的资源消耗,特撰此文。 .NET框架下MD5实现已经集成于System.Web.Security名称空间,只需简单调用即获取结果: string 结果字符串=System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(输入字符串,"MD5"); 以下包装函数根据code参数的不同(可取16或32),分别返回参数STR的16位和32位MD5加密字串。 (16位字串用于模拟动网论坛等国内常见论坛的MD5实现) public string md5(string str,int code) { if(code==16) { return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str,"MD5").ToLower().Substring(8,16) ; } if(code==32) { return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str,"MD5"); } return "00000000000000000000000000000000"; } System.Web.Security名称空间封装的其他方法,可参见MSDN。 *本处以C#为例 由 jinm127 发表于 15:10:30 引用 (0) | 编 辑 回复 发表回复