這篇文章給大家分享的是有關ASP.net中如何使用md5加密碼的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
<%@ 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>
<h4>SHA1加密</h4>
<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加密碼”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。