MD5 Cryptographic operations

Source: Internet
Author: User
Tags hmac

1 //MD5 the encryption of strings2-(void) Demo1 {3NSString *str =@" Love";4     5     //MD5 encryption of strings6str =str.md5string;7     8NSLog (@"str:%@", str);9     Ten     //for a simpler password, you can find it through some websites, such as:http://www.cmd5.com One     //artificially increase the difficulty of the password, you can add salt to the MD5 A     //user password + Salt value MD5 operation -NSString *password =@"312816"; -     //increase the salt value, and the longer (complex) the better theNSString *salt =@"[Email protected]#$%^&*sdfgh"; -     //add salt value to password -Password =[Password Stringbyappendingstring:salt]; -     //Perform MD5 operations +Password =password.md5string; -      +     //add salt, is a more advanced encryption algorithm ANSLog (@"Password:%@", password); at } -  - //HMAC Cryptographic Operations --(void) Demo2 { -     //use block to define a string -__block NSString *password =@"Hello"; in      -     //Create a network request and send toNsurl *url = [Nsurl urlwithstring:@"http://127.0.0.1/login/hmackey.php"]; +      -     //send a network request the[[[Nsurlsession Sharedsession] Datataskwithurl:url completionhandler:^ (NSData * _nullable data, NSURLResponse * _ Nullable Response, Nserror *_nullable Error) { *         //convert JSON data to OC data $Nsdictionary *dict = [nsjsonserialization jsonobjectwithdata:data options:0Error:null];Panax Notoginseng         //define Hmackey -NSString *hmackey = dict[@"Hmackey"]; theNSLog (@"Hmackey:%@", Hmackey); +          A         //use the Hmackey obtained from the server to perform an HMAC on the password thePassword =[Password Hmacmd5stringwithkey:hmackey]; +          -NSLog (@"Password:%@", password); $          $ }] [resume]; -}

MD5 Cryptographic operations

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.