当前位置: 移动技术网 > IT编程>开发语言>.net > ASP.net中md5加密码的方法

ASP.net中md5加密码的方法

2018年04月29日  | 移动技术网IT编程  | 我要评论

langbar.chm,这物患癌前就有!发现早的人都没死,tryout

<%@ page language="c#" contenttype="text/html"%> 
<%@ import namespace="system"%> 
<script language="c#" runat="server"> 
void page_load(object sender,eventargs e){ 
//获取要加密的字段,并转化为byte[]数组 
byte[] data=system.text.encoding.unicode.getbytes(source.text.tochararray()); 
//建立加密服务 
system.security.cryptography.md5 md5 = new system.security.cryptography.md5cryptoserviceprovider(); 
//加密byte[]数组 
byte[] result= md5.computehash(data); 
//将加密后的数组转化为字段 
string sresult=system.text.encoding.unicode.getstring(result); 
//显示出来 
sha1_1.text="md5普通加密:"+sresult.tostring()+"<br/>"; 
//作为密码方式加密 
string enpswdstr=system.web.security.formsauthentication.hashpasswordforstoringinconfigfile(source.text.tostring(),"md5"); 
//显示出来 
sha1_2.text="md5密码加密:"+enpswdstr+"<br/>"; 

</script> 
<html> 
<head> 
<meta http-equiv="content-type" content="text/html; charset=gb2312"> 
<title>测试</title> 
</head> 
<body> 
<h3>sha1加密</h3> 
<form runat="server"> 
<asp:label id="sha1_1" runat="server"></asp:label> 
<asp:label id="sha1_2" runat="server"></asp:label> 
<asp:textbox id="source" runat="server" textmode="singleline" text="test" autopostback="true" /> 
(回车) 
</form> 
</body> 
</html>

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网