欢迎光临
我们一直在努力

初级:.net框架下的MD5-.NET教程,.NET Framework

建站超值云服务器,限时71元/月

近日发现有程序员在.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#为例

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 初级:.net框架下的MD5-.NET教程,.NET Framework
分享到: 更多 (0)

相关推荐

  • 暂无文章