IOS MD5 Encryption

Source: Internet
Author: User
Tags gz file

1.MD5 encryption

Message Digest algorithm MD5 (Chinese named message Digest Algorithm version fifth) is a hash function widely used in the field of computer security to provide integrity protection for messages. The algorithm's file number is RFC 1321 (R.rivest,mit Laboratory for computer science and RSA Data Security Inc. April 1992)

2.MD5 encryption function

Conformance Verification

A typical application of MD5 is to generate an informational digest (message-digest) of a piece of information (message) to prevent tampering. For example, there are a lot of software under Unix that have a file name with the same filename and file extension. MD5 in this file, usually with a single line of text, roughly structured like this:

MD5 (tanajiya.tar.gz) = 0ca175b9c0f726a831d895e269332461

This is the digital signature of the tanajiya.tar.gz file. MD5 the entire file as a large text message, through its irreversible string transform algorithm, produces this unique MD5 message digest. In order to make readers ' friends have an intuitive understanding of the application of MD5, the author gives a brief description of the work process with an analogy and an example: everyone knows that anyone on earth has their own unique fingerprints, which often becomes the most trustworthy way for the judicial authorities to identify criminals; similarly, MD5 can produce an equally unique "digital fingerprint" for any file (regardless of size, format, number), and if anyone makes any changes to the file, its MD5 value, or the corresponding "digital fingerprint", will change. We often see its MD5 value in some software download site, it is the function that we can download the software, the downloaded file with special software (such as Windows MD5 Check, etc.) to do a MD5 check, To ensure that the files we obtain are the same files as the files provided by the site. The scheme of file checking using MD5 algorithm is widely used in software download station, forum database, System file security and so on. Digital CertificatesA typical application of MD5 is to generate fingerprint (fingerprints) on a message (byte string) to prevent "tampering". For example, you will write a paragraph in a message called Readme.txt file, and on this Readme.txt generate a MD5 value and record, and then you can spread this file to others, if others modify any of the contents of the file, you will see this file recalculation MD5 (two MD5 values are not the same). If there is a third-party certification body, with MD5 can also prevent the file author's "Repudiation", which is called Digital signature application.Secure access authenticationMD5 is also widely used in operating system login authentication, such as UNIX, all kinds of BSD system login password, digital signature and many other aspects. For example, in Unix system, the user's password is stored in the file system by MD5 (or other similar algorithm) after hash operation. When the user logs in, the system MD5 the user's password into a hash, and then compares the MD5 value stored in the file system to determine if the password was entered correctly. Through such steps, the system can determine the legality of the user login system without knowing the user's password. This avoids the user's password being known to users who have system administrator privileges. MD5 map any length of "byte string" to a large integer of 128bit, and it is difficult to reverse the original string through the 128bit, in other words, even if you see the source program and algorithm description, you can not transform a MD5 value back to the original string, mathematically speaking, This is because the original string has an infinite number, which is somewhat like a mathematical function that does not have an inverse function. Therefore, to encounter the problem of MD5 password, the better way is: You can use the MD5 () function in this system to reset a password, such as admin, the generated hash of a string of passwords to overwrite the original hash value on the line. It is for this reason that the most commonly used hacker to decipher a password is a method called "Running a dictionary". There are two ways to get a dictionary, one is the daily collection of strings used for the password table, and the other is generated by the arrangement of the combination of methods, the first use MD5 program to calculate the MD5 value of these dictionary items, and then use the target MD5 value in the dictionary to retrieve. We assume that the maximum length of the password is 8 bytes (8 Bytes), and that the password can only be letters and numbers, a total of 26+26+10=62 characters, and the number of items in the sorted dictionary is P (62,1) +p (62,2) .... +p (62,8), which is already a very astronomical figure, Storing this dictionary requires a terabytes of disk array, and there is a premise that it is possible to obtain the password MD5 value of the target account. This encryption technique is widely used in UNIX systems, which is one of the important reasons why UNIX systems are more robust than general operating systems. MD5 (1) MD5 encrypted string implemented in 3.iOS

The string is MD5 encrypted, returning the encrypted string.  

#import <CommonCrypto/CommonDigest.h>//need to import for CC_MD5 access
-(NSString *) MD5: (NSString *) str{    const char *CSTR = [str utf8string];    unsigned char result[16];    CC_MD5 (CStr, strlen (CSTR), result); The MD5 call
Output 1// return [nsstring stringwithformat:// @ "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x %02x%02x ",// result[0], result[1], result[2], result[3],// result[4], result[5], result[6], result[7],// result[8], result[9], result[10], result[11],// result[12], result[13], result[14], result[15]//

Output 2 simplified version
nsmutablestring *ret = [nsmutablestring stringwithcapacity:cc_md5_digest_length];

for (int i = 0; i<cc_md5_digest_length; i++) {
[ret appendformat:@ "%02x", result];
}
return ret;
}

IOS MD5 Encryption

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.