MD5
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. is an irreversible encryption algorithm, is currently one of the most reliable encryption algorithm, there is no inverse operation of the program was developed, it corresponds to any string can be encrypted into a unique fixed length of code.
Characteristics:
First of all, it is not reversible, there is no systematic way to know MD5 code original text is what
Secondly, this code has a high degree of dispersion, there is no law to follow. Even a little change in the original information will lead to a great change in the MD5, and it can be said that the resulting MD5 code is unpredictable.
Finally, because the code is 128 bits long, the possibility of having the same MD5 code between arbitrary information is very low and is often considered impossible.
Use:
It is generally believed that MD5 code can uniquely represent the characteristics of the original information, usually used for cryptographic storage of passwords, digital signatures, file integrity verification, etc.
Usage Example:
Copy Code code as follows:
private string GetMD5 (string code)
{
if (! String.IsNullOrEmpty (code))
{
Return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile (Code, "MD5"). ToLower ();
}
Else
{
return string. Empty;
}
}
SHA1
SHA1 's full name is Secure Hash algorithm (secure hashing algorithm), which is designed by the NIST NSA to work with DSA, which produces a 160bit hash value for a length of less than 264, and therefore has a better anti-poor (brute-force) nature. The SHA-1 design is based on the same principle as the MD4 and imitates the algorithm. SHA-1, a national standard promulgated by the United States Standards Technology Agency (NIST), is one of the most widely used hash function algorithms and the most advanced encryption technology currently used by government departments and private owners to handle sensitive information. and SHA-1 based on MD5,MD5 and MD4.
SHA-1 more than MD5 32-bit ciphertext, so more secure. For the same reason, MD5 is faster than SHA-1.
Usage Example:
Copy Code code as follows:
private string Getsha (string code)
{
if (! String.IsNullOrEmpty (code))
{
Return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile (Code, "SHA1"). ToLower ();
}
Else
{
return string. Empty;
}
}
Note: Since both cryptographic algorithms are irreversible, the original text needs to be encrypted before the information is corrected. If the user forgets the password, only the user's password can be reset.