There are several IOS encryption algorithms, such as Md5,sha1,aes,base64 and RSA.
1. MD5:
MD5 is message-digest algorithm 5 (Information-Digest algorithm 5), which is used to ensure complete and consistent information transmission. is one of the widely used hashing algorithms (also translation digest algorithm, hashing algorithm), mainstream programming language has been widely MD5 implemented. MD5 's role is to allow bulk information to be "compressed" into a confidential format before signing a private key with a digital signature software (that is, converting an arbitrary-length byte string into a long hexadecimal string ). (quoted from Baidu Encyclopedia)
MD5 encryption is not reversible at the moment.
The MD5 algorithm produces a fixed 128bit, that is, 128 0 and 1 of the bits, and in the actual application development, usually in the 16-input output, so exactly 32 bits of the 16 number, plainly speaking is 32 16 decimal numbers.
-(NSString *) MD5: (Nsdictionary *) paramsdict {nsstring*instring = [Paramsdict stringvalueforkey:@"Data"DefaultValue:@""]; if(Instring.length <=0) { return @""; } Else { Const Char*cstrvalue =[instring utf8string]; //open up a 16-byte (128-bit: MD5 encrypted out of 128-bit/bit) space (one byte = 8 bits = 8 binary numbers)UnsignedCharOutresult[cc_md5_digest_length]; CC_MD5 (Cstrvalue, strlen (cstrvalue), outresult); //x is hexadecimal, x means less than two bits will be padded with 0, if the extra two digits do not affectNSString *outstring =[NSString stringWithFormat:@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", outresult[0], outresult[1], outresult[2], outresult[3], outresult[4], outresult[5], outresult[6], outresult[7], outresult[8], outresult[9], outresult[Ten], outresult[ One], outresult[ A], outresult[ -], outresult[ -], outresult[ the]]; /*//Method Two: Nsmutablestring *outstring = [nsmutablestring string]; for (int i = 0; i < i++) {[outstring appendformat:@ "X", Outresult[i]]; } */ returnoutstring; } }
Why is [16], this is because the MD5 algorithm last generated 128 bits, and the smallest storage unit in the computer is a byte, 1 bytes is 8 bits, corresponding to a char type, the calculation can require 16 char. So result is [16]. So why is the format of the output must be%02x, not the other one? This is also a reason: because the Convention MD5 is generally in 16 binary format output, then in fact, the problem is converted to 128 0 and 1 in 16 binary, each 4 binary corresponding to a 16 element, you need 32 16 elements, if the element is all 0, put into the array of char, Normal is not output, such as 00001111, to the output of%x, then F, then will be lost 0, but if the output is a%02x representation of the result is 0f, is exactly the correct result of the conversion.
2. SHA1 encryption
Some specifics about IOS encryption