MD5 and SHA1 encryption algorithm--A large integer md5:128bit hash encryption technology

Source: Internet
Author: User
Tags md5 encryption sha1 sha1 encryption

In many e-commerce and community applications, we have to store a lot of customer information, including a lot of private information and customers do not want to be seen by the information, of course, the customer to perform various operations of the password, at this time need to encrypt the customer's information and storage, There are two kinds of better encryption algorithms: MD5 and SHA1.

Both of these cryptographic algorithms belong to hash encryption technology. The so-called hash encryption is that no matter what the input string is, how large, after the encryption will become a unique fixed-length encryption string.

First of all, the full name of MD5,MD5 is Message-digest algorithm 5, developed by the MIT Computer Science Lab and RSA Data Security Inc in the early 90, through MD2, MD3 and MD4. Message-digest refers to a hash transformation of a byte string (Message), which transforms a byte string of any length into a long, large integer. Note that a "byte string" is not a "string" because the transformation is only related to the value of the byte, regardless of the character set or encoding. MD5 will be arbitrary length of "byte string" into a large integer 128bit, and this is an irreversible transformation process, to crack can only be poor lifting, difficult, theoretically 8-bit cipher combination has (26 letters +10 digits +21 commonly used English symbols) 8 species may, It takes more than a year to count the machines that are better now. MD5 encrypted string length has 16-bit and 32-bit two kinds. But recently MD5 heard to have been cracked (heard or by our countrymen broke, admire Ah!) ), can quickly crash to the password, but the cracker has not yet spread out.

A typical application of MD5 is to generate fingerprint (fingerprints) on a message (byte string) to prevent "tampering". For example, you write a paragraph in a file called Readme.txt, and you create a MD5 value for the Readme.txt and record it, and then you can spread the file to someone else, and if someone modifies anything in the file, you'll find it when you recalculate the MD5. If there is a third-party certification body, with MD5 can also prevent the file author's "Repudiation", which is called Digital signature application.

The MD5 encryption algorithm is well supported in Microsoft Visual Studio 2005 and is very simple to use, with the following examples of using MD5 to encrypt strings in C #:

public string MD5 (string Str,int code) {if (code==16)//16-bit MD5 encryption (take 32-bit encrypted 9~25 character) {return System.Web.Securi Ty. FormsAuthentication.

HashPasswordForStoringInConfigFile (str, "MD5"). ToLower ().     Substring (8,16); } else//32 bit encryption {return System.Web.Security.FormsAuthentication.

HashPasswordForStoringInConfigFile (str, "MD5").     ToLower (); } }

The cipher string with the SHA1 algorithm has a 40-bit length and is relatively more secure.

The use of SHA1 in Microsoft Visual Studio 2005 is also simple, as shown here is an example of using SHA1 to encrypt strings in C #:

public string SHA1 (String str) {return System.Web.Security.FormsAuthentication.

HashPasswordForStoringInConfigFile (str, "SHA1").         ToLower (); }

But in the end there is an unfortunate news that the SHA1 algorithm has been cracked, and the National Institute of Standards and Technology (nationally Institute of Standards and technology) has recommended the use of sha-256 or sha-512 algorithms.

MD5 and SHA1 encryption algorithm--A large integer md5:128bit hash encryption technology

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.