iOS storage Security MD5 (important)

Source: Internet
Author: User

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)

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.