溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

ASP.net中如何使用md5加密碼

發(fā)布時間:2021-01-29 16:01:25 來源:億速云 閱讀:156 作者:小新 欄目:編程語言

這篇文章給大家分享的是有關ASP.net中如何使用md5加密碼的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。

<%@ 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());  
//建立加密服務  
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>  
<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加密碼”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI