<% @ Page Language = "C #" ContentType = "text/html" %>
<% @ Import Namespace = "System" %>
<Script language = "C #" runat = "server">
Void Page_Load (Object sender, EventArgs e ){
// Obtain the field to be encrypted and convert it to a Byte [] Array
Byte [] data = System. Text. Encoding. Unicode. GetBytes (source. Text. ToCharArray ());
// Create an encryption service
System. Security. Cryptography. MD5 md5 = new System. Security. Cryptography. MD5CryptoServiceProvider ();
// Encrypt Byte [] Arrays
Byte [] result = md5.ComputeHash (data );
// Convert the encrypted array into a field
String sResult = System. Text. Encoding. Unicode. GetString (result );
// Display
Sha1_1.Text = "MD5 common encryption:" + sResult. ToString () + "<br/> ";
// Encrypted as a password
String EnPswdStr = System. Web. Security. FormsAuthentication. HashPasswordForStoringInConfigFile (source. Text. ToString (), "MD5 ");
// Display
Sha1_2.Text = "MD5 password encryption:" + EnPswdStr + "<br/> ";
}
</Script>
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> test </title>
</Head>
<Body>
<H3> SHA1 encryption <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"/>
(Press ENTER)
</Form>
</Body>
</Html>