The full name of MD5 is message-digest algorithm 5 (Information-Digest algorithm), in the early 90 by MIT Laboratory for Computer and RSA Data Security Inc, Ronald L. Riv EST developed and developed by MD2, Md3 and MD4. Its role is to allow bulk information to be "compressed" into a confidential format (that is, to transform a byte string of any length into a long, large integer) before signing the private key with the digital signature software. Whether they are MD2, MD4, or MD5, they need to obtain a random length of information and produce a 128-bit summary of the information.
The cryptographic hash function maps a binary string of any length to a small binary string of fixed length. The cryptographic hash function has the property that it is not possible to find two different inputs with the same value in the calculation, that is, the hash value of the two sets of data matches only if the corresponding data matches. A small amount of change in the data produces unpredictable and significant changes in the hash value. So it's hard to find clues from the encrypted text.
The full name of SHA1 is secure Hash algorithm (Secure Hash Algorithm)
The hash value of the MD5 algorithm is 128 bits in size. The hash value of the SHA1 algorithm is 160 bits in size. Both of these algorithms are irreversible.
Although August 17, 2004 at the International Cryptography Conference in Santa Barbara, Calif. (Crypto ' 2004), Professor Wangxiaoyun of the University of Shandong, China, made a report deciphering the MD5, HAVAL-128, MD4 and RIPEMD algorithms, releasing the results of the MD series algorithm. Declared an impregnable world password standard MD5 fortress collapsed, triggering a firestorm in the field of cryptography. But I think that for us to do ordinary software, this encryption security level is enough to use.
We usually use the most is nothing but encrypt the user password, the encrypted password stored in the database, password comparison, the user entered the password to encrypt again, and then the database with the ciphertext to compare. As for the ASP.net class is how to implement the encryption algorithm, which we do not need to care, will be used on the line.
Here are several encryption methods in asp.net. There are two cryptographic algorithms, the above mentioned MD5 and SHA1, here I cite the example of MD5, SHA1 roughly the same, but the use of different classes.
MD5 Related classes:
Copy Code code as follows:
System.Security.Cryptography.MD5
System.Security.Cryptography.MD5CryptoServiceProvider ()
System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile (strsource, "MD5")
SHA1 Related classes:
Copy Code code as follows:
System.Security.Cryptography.SHA1
System.Security.Cryptography.SHA1CryptoServiceProvider ()
System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile (strsource, "SHA1")
The method is as follows: (used vs2005)
Copy Code code as follows:
/**////<summary>
Method One: Create an object by using the new operator
</summary>
<param name= "strsource" > Need encrypted plaintext </param>
<returns> returns 16-bit encryption results, which take the 9th to 25 bits of 32-bit encryption results </returns>
public string Get_md5_method1 (string strsource)
{
New
System.Security.Cryptography.MD5 MD5 = new System.Security.Cryptography.MD5CryptoServiceProvider ();
Get an array of dense text sections
byte[] Bytresult = Md5.computehash (System.Text.Encoding.Default.GetBytes (strsource));
Converts to a string and takes 9 to 25 bits
String strresult = Bitconverter.tostring (Bytresult, 4, 8);
Convert to String, 32-bit
String strresult = Bitconverter.tostring (Bytresult);
Bitconverter the converted string produces a delimiter in the middle of each character and needs to be removed
strresult = Strresult.replace ("-", "");
return strresult;
}
/**////<summary>
Method Two: Creates an object that implements a particular cryptographic algorithm by invoking the Create method on the abstract class of a particular cryptographic algorithm.
</summary>
<param name= "strsource" > Need encrypted plaintext </param>
<returns> return 32-bit encryption results </returns>
public string Get_md5_method2 (string strsource)
{
String strresult = "";
Create
System.Security.Cryptography.MD5 MD5 = System.Security.Cryptography.MD5.Create ();
Pay attention to the choice of encoding UTF8, UTF7, Unicode, etc.
byte[] Bytresult = Md5.computehash (System.Text.Encoding.UTF8.GetBytes (strsource));
Converts an array of byte types to a string
for (int i = 0; i < bytresult.length; i++)
{
16 in-Process conversion
strresult = Strresult + bytresult[i]. ToString ("X");
}
return strresult;
}
/**////<summary>
Method Three: Directly using HashPasswordForStoringInConfigFile generation
</summary>
<param name= "strsource" > Need encrypted plaintext </param>
<returns> return 32-bit encryption results </returns>
public string get_md5_method3 (string strsource)
{
Return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile (strsource, "MD5");
}
These cryptographic functions are executed on the server side, that is, when the user enters the password, from the client to the server side of the transmission, the user's password is not protected, very dangerous. The bank's approach is to install ActiveX controls on the client, encrypt some important information on the client, and then send it. This I will not pull, I would like to learn to do this ActiveX control.