欢迎光临
我们一直在努力

[我的ASP.net学习历程]调用类库函库的简单加密方法-.NET教程,Asp.Net开发

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

asp.net自带了一个md5和sha1加密类库!

下面是调用此类库的两种加密方法:

=====================

public string getmd5(string strdata)

{

//使用md5加密方法:

system.security.cryptography.md5 md5 = new system.security.cryptography.md5cryptoserviceprovider();

byte[] md5bytes = system.text.encoding.default.getbytes(strdata);

byte[] crystring = md5.computehash(md5bytes);

string md5str = string.empty;

for (int i=0;i<crystring.length;i++)

{

md5str += crystring[i].tostring("x2");

}

return md5str;

}

public string getencrypt(string strdata,string strtype)

{

//使用md5或sha1的加密方法:

string strcrydata = string.empty;

if (strtype.toupper() == "sha1")

{

strcrydata = system.web.security.formsauthentication.hashpasswordforstoringinconfigfile(strdata,"sha1");

}

else if (strtype.toupper() == "md5")

{

strcrydata = system.web.security.formsauthentication.hashpasswordforstoringinconfigfile(strdata,"md5");

}

return strcrydata;

}

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » [我的ASP.net学习历程]调用类库函库的简单加密方法-.NET教程,Asp.Net开发
分享到: 更多 (0)

相关推荐

  • 暂无文章