如何使用MD5技术加密

如何使用MD5技术加密

前台
<%@ Import Namespace="System"%>
<HTML>
 <HEAD>
  <title>测试</title>
  <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
 </HEAD>
 <body>
  <h3>SHA1加密</h3>
  <form runat="server" ID="Form1">
   <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>

 

CS代码
private void Page_Load(object sender, System.EventArgs e)
  {
   byte[] data=System.Text.Encoding.Unicode.GetBytes(source.Text.ToCharArray());
 
   System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();

   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/>";
  }

你可能感兴趣的:(加密,String,server,asp,byte,textbox)