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