Objective
In the process of software development, encryption of data is an important means to ensure data security, and common encryption has Base64 encryption and MD5 encryption. BASE64 encryption is reversible, and MD5 encryption is now generally irreversible.
MD5 generates a fixed 128bit, that is, 128 0 and 1 bits, and in the actual application development, is usually 16 in the output, so exactly is 32-bit 16, the white is 32 16 into the number.
MD5 main feature is irreversible, the same data MD5 value is certainly the same, different data MD5 value is not the same (nor absolute, but basic is not the same).
The MD5 algorithm also has the following properties:
1, compressibility: Arbitrary length of data, calculated MD5 value of the length are fixed.
2, easy to calculate: From the original data calculated MD5 value is very easy.
3, resistance to modification: Any changes to the original data, even if only modify 1 bytes, the resulting MD5 values are very different.
4, weak anti-collision: Known the original data and its MD5 value, it is very difficult to find a data with the same MD5 value (that is, forged data).
5, strong anti-collision: To find two different data, so that they have the same MD5 value, is very difficult.
6, MD5 encryption is not decrypted, but there are some analytic MD5 on the Internet, that is equivalent to a large database, through matching MD5 to find the original password. So, as long as the string to be encrypted preceded by a number of alphanumeric symbols or multiple MD5 encryption, the result is generally not resolved.
Application of MD5:
Because the MD5 encryption algorithm has good security, and free, so the encryption algorithm is widely used
Most login features use this algorithm when submitting passwords to the background
Note the point:
(1) must be with the background developer agreed, MD5 encryption of the number of digits is 16 or 32 (most of them are 32 bits), 16-bit can be converted through 32-bit conversion.
(2) MD5 encryption is case-sensitive and is used in a background agreement.
MD5 decryption:
Decryption site: http://www.cmd5.com/
Many other methods, such as salt, have emerged in order to make the MD5 code more secure. It is difficult to find the MD5 code that is long enough for the salt to be found.
Terminal code: $ echo-n ABC|OPENSSL MD5 to string ABC encryption,
Apple packs the MD5 encryption method, which is very convenient to use.
#import @interface Md5encrypt:nsobject//MD5 encryption/* Because MD5 encryption is irreversible and is used for verification *///32 bit lowercase + (N
Sstring *) Md5forlower32bate: (NSString *) str;
32-bit Uppercase + (NSString *) Md5forupper32bate: (NSString *) str;
16 is capital + (NSString *) Md5forupper16bate: (NSString *) str;
16-bit lowercase + (NSString *) Md5forlower16bate: (NSString *) str; @end
#import "MD5Encrypt.h" #import <CommonCrypto/CommonDigest.h> @implementation md5encrypt #pragma mark-32 bit lowercase + (N
Sstring *) Md5forlower32bate: (NSString *) str{//To be UTF8 the transcoding const char* input = [str utf8string];
unsigned char result[cc_md5_digest_length];
CC_MD5 (input, (cc_long) strlen (input), result);
nsmutablestring *digest = [nsmutablestring stringwithcapacity:cc_md5_digest_length * 2];
for (Nsinteger i = 0; i < cc_md5_digest_length; i++) {[DIGEST appendformat:@ '%02x ', result[i]];
return digest; #pragma mark-32-bit uppercase + (NSString *) Md5forupper32bate: (NSString *) str{//UTF8 transcoding const char* input = [str utf8st
Ring];
unsigned char result[cc_md5_digest_length];
CC_MD5 (input, (cc_long) strlen (input), result);
nsmutablestring *digest = [nsmutablestring stringwithcapacity:cc_md5_digest_length * 2];
for (Nsinteger i = 0; i < cc_md5_digest_length; i++) {[DIGEST appendformat:@ '%02x ', result[i]];
return digest; #pragma mark-16-bit Uppercase + (NSString *) Md5forupper16bate: (NSString *) str{nsstring *md5str = [self md5forupper32bate:str];
NSString *string;
for (int i=0; i<24; i++) {string=[md5str Substringwithrange:nsmakerange (8, 16)];
} return string; #pragma mark-16 bit lowercase + (NSString *) Md5forlower16bate: (NSString *) str{nsstring = [Self *md5str
R];
NSString *string;
for (int i=0; i<24; i++) {string=[md5str Substringwithrange:nsmakerange (8, 16)];
} return string; } @end
Summarize
Above is the iOS MD5 encryption algorithm introduction and the use, hoped can have the help for the iOS developer, if has the question everybody may the message exchange.