If the project involves login registration etc.
You need to consider password encryption at this point.
The specific implementation under iOS is as follows
Create a new class inheritance
#import <Foundation/Foundation.h> #import <CommonCrypto/CommonDigest.h> @interface md5:nsobject/*** MD5 encryption, incoming strings that need to be encrypted, irreversible * * * @param str needs an encrypted string * * @return Encrypted string */+ (NSString *) MD5: (NSString *) str; @end
Implementation of the class
#import "MD5.h" @implementation md5+ (NSString *) MD5: (NSString *) str{ const char *CSTR = [str utf8string]; unsigned char result[16]; CC_MD5 (CStr, strlen (CSTR), result); The MD5 call NSString * string = [NSString stringWithFormat: @ "%02x%02x%02x%02x%02x%02x%02x%02x %02x%02x%02x%02x%02x%02x%02x%02x ", result[0], result[1], result[2], result[3], result[4], result[5], result [6], result[7], result[8], result[9], result[10], result[11], result[12], result[13], result[14], result[15]< c10/>]; return [string Substringwithrange:nsmakerange (8, 16)];} @end
Specific use
NSString *[email protected] "ready to encrypt"; NSString *str1=[md5 Md5:str]; NSLog (@ "str=%@,str1=%@", STR,STR1);
Output results
testmd5[659:20205] str= Preparing for encryption , Str1=54a96da37e422e51
I'm looking for an encryption tool on the Internet to test it.
Okay, basically, you can use it.
What is the problem can add QQ Chat
Apple Development Group: 414319235 Welcome to Join
IOS MD5 Encryption algorithm