Share a man-written encryption classification, the notes are quite clear.
Security.zip
Encryption scheme
Scenario One: Direct MD5 is very unsafe ( exhaustive hack )
PWD = pwd.md5string;
Solution two MD5 + salt salt value is "salty", can be obtained from the server
PWD = [pwd stringbyappendingstring:@ "irregular complex salts"].md5string;
Security Scenario Three-HMAC
PWD = [pwd hmacmd5stringwithkey:@ "key"];
Relative to the previous scenario, the security level is much higher, using ' key ' to ' encrypt ' the PWD, then MD5, then encrypt again, MD5
Security scenario Four-timestamp password (local time may be inconsistent with server, preferably time taken from server)
Ensure that different times of transmission of the password are not the same, the server to judge the current minute and the first minute. The password is valid for two minutes.
To encrypt a password in time-stamped
-(nsstring*) Timepassword: (nsstring*) pwd{
1. Generate MD5 for key
NSString *key = @ "Weijing_yun". md5string;
NSLog (@ "key:%@", key);
2. Use key to encrypt the password for HMAC
NSString *pwdkey = [pwd Hmacmd5stringwithkey:key];
3. Take the current server system time put on the main thread execution to change the back timestamp
Nsurl *url = [Nsurl urlwithstring:@ "http://127.0.0.1/hmackey.php"];
Using synchronization to get time
NSData *data = [NSData Datawithcontentsofurl:url];
Deserialization
Nsdictionary *dict = [nsjsonserialization jsonobjectwithdata:data options:0 error:null];
Remove Date string
NSString *datestr = dict[@ "Key"];
NSLog (@ "Time%@", datestr);
4. Password + timestamp
Pwdkey = [Pwdkey stringbyappendingstring:datestr];
NSLog (@ "%@", Pwdkey);
5. Use HMAC encryption again
return [Pwdkey Hmacmd5stringwithkey:key];
}
iOS storage Security MD5 (important)