MD5 encryption in iOS development practices

Source: Internet
Author: User

MD5 encryption in iOS development practices

What is MD5:

Message Digest Algorithm 5 (Message Digest Algorithm version 5th"

Effect: generate a unique 128-bit hash value for the input information (32 characters)

MD5 features:

Two different plaintext values are input, and the same output value is not obtained.

According to the output value, the original plain text cannot be obtained, that is, the process is irreversible.

MD5 application:

The MD5 encryption algorithm is widely used because it is secure and free of charge.

It is mainly used in digital signatures, file integrity verification, and password encryption.

MD5 improvements:

Add Salt (Salt): Insert a random string at a fixed position in the plain text, and then perform MD5

Encryption first, followed by out-of-order: MD5 is performed on the plaintext, and then the characters in the encrypted MD5 string are in out-of-order.

Chestnuts:

Import NSString + hash. h encapsulated encryption classification algorithm: http://pan.baidu.com/s/1o7hA4Vw

ViewController. m

// ViewController. m # import "ViewController. h "# import" NSString + Hash. h "@ interface ViewController () @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad]; [self MD5]; [self MD5Salt: @" san "]; [self doubleMD5]; [self MD5Reorder];} // MD5 encryption-(void) MD5 {NSString * pwd = @ "123456"; NSString * pwdMD5 = [pwd md5String]; NSLog (@ "% @", pwdMD5);}/*** salt encryption MD5 ($ pass. $ salt) */-(void) MD5Salt :( NSString *) salt {NSString * pwd = @ "123456"; pwd = [pwd stringByAppendingString: salt]; // salt: randomly insert any string NSString * pwdMD5 = [pwd md5String]; NSLog (@ "% @", pwdMD5 );} /*** MD5 (MD5 ($ pass) */-(void) doubleMD5 {NSString * pwd = @ "123456 "; NSString * pwdMD5MD5 = [[pwd md5String] md5String]; NSLog (@ "% @", pwdMD5MD5);}/*** encrypt first, then unordered */-(void) MD5Reorder {NSString * pwd = @ "123456"; NSString * pwdMD5 = [pwd md5String]; NSLog (@ "oldpwdMD5 = % @", pwdMD5 ); NSString * prefix = [pwdMD5 substringFromIndex: 3]; // capture (including 3) NSString * subfix = [pwdMD5 substringToIndex: 3] starting from the subscript 3; // truncate a string from 0 to 3 (excluding 3) pwdMD5 = [prefix stringByAppendingString: subfix]; NSLog (@ "newpwdMD5 = % @", pwdMD5);} @ end

Related Article

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.