ASP.net中md5加密码的方法

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 web718 的 blog

<%@ 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>

本文关键:ASP.net中md5加密码的方法
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top