這篇文章主要介紹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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。