|
What is the difference between ordinary encryption and password encryption used in the following, and where are they suitable for use?
<% @ Page Language = "C #" ContentType = "text / html"%>
<% @ Import Namespace = "System"%>
<script language = "C #" runat = "server">
void Page_Load (Object sender, EventArgs e) {
// Get the field to be encrypted and convert it into a Byte [] array
byte [] data = System.Text.Encoding.Unicode
.GetBytes (source.Text.ToCharArray ());
// Establish encryption service
System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider ();
// Encrypt Byte [] array
byte [] result = md5.ComputeHash (data);
// Convert the encrypted array into a field
string sResult = System.Text.Encoding.Unicode.GetString (result);
//show
sha1_1.Text = "MD5 ordinary encryption:" + sResult.ToString () + "<br/>";
// Encrypt as password
string EnPswdStr = System.Web.Security.FormsAuthentication.
HashPasswordForStoringInConfigFile (source.Text.ToString (), "MD5");
//show
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 </ h3>
<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" />
(Enter)
</ form>
</ body>
</ html> |
|