. H file
/*** MD5 encryption tool */# import <Foundation/Foundation. h> @ interface md5tools: nsobject/*** MD5 encryption */+ (nsstring *) MD5 :( nsstring *) value;/*** the last four digits of the password MD5 + mobile phone number, perform MD5 encryption */+ (nsstring *) md5psd :( nsstring *) password withphonenum :( nsstring *) phonenum; @ end
. M file
# Import "md5tools. H "# import <commoncrypto/commondigest. h> @ implementation md5tools + (nsstring *) MD5 :( nsstring *) value {const char * CSTR = [value utf8string]; unsigned char result [16]; cc_md5 (CSTR, strlen (CSTR), result); // This is the MD5 call return [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];} + (nsstring *) md5psd :( nsstring *) password withphonenum :( nsstring *) phonenum {nsstring * STR = [nsstring stringwithformat: @ "% @", [md5tools MD5: Password], [[phonenum substringfromindex: phonenum. length-4] substringtoindex: 4]; return [md5tools MD5: Str] ;}@ end