ASP.net中md5加密碼的方法
更新時(shí)間:2006年07月17日 00:00:00 作者:
<%@ Page Language="C#" ContentType="text/html"%>
<%@ Import Namespace="System"%>
<script language="C#" runat="server">
void Page_Load(Object sender,EventArgs e){
//獲取要加密的字段,并轉(zhuǎn)化為Byte[]數(shù)組
byte[] data=System.Text.Encoding.Unicode.GetBytes(source.Text.ToCharArray());
//建立加密服務(wù)
System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
//加密Byte[]數(shù)組
byte[] result= md5.ComputeHash(data);
//將加密后的數(shù)組轉(zhuǎn)化為字段
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>
<%@ Import Namespace="System"%>
<script language="C#" runat="server">
void Page_Load(Object sender,EventArgs e){
//獲取要加密的字段,并轉(zhuǎn)化為Byte[]數(shù)組
byte[] data=System.Text.Encoding.Unicode.GetBytes(source.Text.ToCharArray());
//建立加密服務(wù)
System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
//加密Byte[]數(shù)組
byte[] result= md5.ComputeHash(data);
//將加密后的數(shù)組轉(zhuǎn)化為字段
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中DES加密與解密MD5加密幫助類的實(shí)現(xiàn)代碼
- VB.NET實(shí)現(xiàn)的MD5加密算法示例【32位】
- .NET MD5加密解密代碼解析
- asp.net實(shí)現(xiàn)的MD5加密和DES加解密算法類完整示例
- asp.net實(shí)現(xiàn)md5加密
- vb 中的MD5加密在asp.net中的實(shí)現(xiàn)
- asp.net中使用cookie與md5加密實(shí)現(xiàn)記住密碼功能的實(shí)現(xiàn)代碼
- ASP.NET中MD5與SHA1加密的幾種方法
- 徹底解決ASP.NET MD5加密中文結(jié)果和ASP不一致的問題
- asp.net下常用的加密算法MD5、SHA-1應(yīng)用代碼
- asp.net中MD5 16位和32位加密函數(shù)
- .net core使用MD5加密解密字符串
相關(guān)文章
.NET?中配置從xml轉(zhuǎn)向json方法示例詳解
這篇文章主要為大家介紹了.NET?中配置從xml轉(zhuǎn)向json方法示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11.Net性能調(diào)優(yōu)-ArrayPool詳情
ArrayPool具有高性能 托管 數(shù)組緩沖池,可重復(fù)使用,用 租用 空間的方式代替 重新分配 數(shù)組空間的行為的特點(diǎn)及可以在頻繁創(chuàng)建和銷毀數(shù)組的情況下 提高性能 ,減少垃圾回收器的壓力的優(yōu)點(diǎn),下面文章內(nèi)容將詳細(xì)對其做介紹,需要的朋友可以參考一下2021-09-09