IOS Encryption: MD5

Source: Internet
Author: User
Tags md5 encryption

MD5: First, MD5 is not encrypted.

MD5 is a digest algorithm, mainly used to do authentication, using its own advantages (irreversible, low collision rate) to solve the public network Exchange keys, authentication problems,

MD5 is equivalent to a super-loss compression, in the calculation of the original part of the information will be lost.

MD5 Why not reversible? Example:

Original:
come on, like, Kiss.
Encryption Rules:
each word with phonetic tone + stroke number, the final result of the product, in order to also make my results always remain within a limited range, take the final result and the remainder of the 2^14=16384 (whatever you want, I have a binary OCD)
such as fast is 7 draw, 4 sound, that is, "eigenvalue 11", and so on point 9+3=12 like 16+4=20 ah 10+4=14 Pro 9+1=10
Finally, the irreversible function value I invented is
the remainder of 11*12*20*14*10=26400 and 16384, i.e. 10016
If you just give 10016 this number and encryption algorithm, you are not able to pull out the original text is "Quick praise Ah Pro", but if you "quick praise Ah Pro" You can easily verify that the answer is correct.

What's the use of signing? Example:

Encryption is designed to protect the privacy of plaintext (privacy) and prevent privacy leaks. Imagine a pair of young Alice and Bob are still ambiguous, two people secretly go to dinner, do not want to let others know. Alice wants to tell Bob what time to go to dinner on a date today, but doesn't want anyone else (who can be abstracted to be an abstraction for all the others represented by her rival Carol) to know about their meal times and use encryption. After encryption, the decryption can recover from ciphertext (ciphertext) clear text (plaintext), that is, meal time.

when you get to the Mac, the scene changes. This time Alice and Bob the Small (Gou) Blue (Nan) year (NV) relationship has been very stable, no secret. But rival Carol still exist, Zeixinbusi. Alice at this time is not afraid of two people to date dinner time was seen by others, she is afraid of rival tampering time, let two people can not meet. So she sends the time in clear text and then attaches the Mac to this time. Carol if the time is tampered with, then the MAC is not in the care of. That is, this is not to protect the privacy of the date, but to protect its integrity (integrity). (this link comes to know: http://www.zhihu.com/question/25104607/answer/38888836)

MD5 on iOS is used:

Apple has packaged the MD5 encryption method, which is very convenient to use.

1. import Header File

    1. #import <CommonCrypto/CommonDigest.h>

2, the method of encryption:

-(NSString *) MD5: (NSString *) input {
const char *CSTR = [input utf8string];
unsigned char digest[cc_md5_digest_length];
CC_MD5 (CStr, strlen (CSTR), Digest); The MD5 call

nsmutablestring *output = [nsmutablestring stringwithcapacity:cc_md5_digest_length * 2];

for (int i = 0; i < cc_md5_digest_length; i++)
[Output appendformat:@ "%02x", Digest[i]];

return output;
}

3. Call the Encryption method:

NSString *str = @ "123456";

NSString *result = [self md5:str];

NSLog (@ "%@", result);

Results of the output:

IOS encryption: MD5

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.