IOS MD5 Encryption algorithm
1 #import<CommonCrypto/CommonDigest.h>//need to import for CC_MD5 access2 3 4-(NSString *) MD5: (NSString *) Str5 {6 Const Char*cstr =[str utf8string];7UnsignedCharresult[ -];8CC_MD5 (CStr, strlen (CSTR), result);//The MD5 call9 return[NSString stringWithFormat:Ten @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", Oneresult[0], result[1], result[2], result[3], Aresult[4], result[5], result[6], result[7], -result[8], result[9], result[Ten], result[ One], -result[ A], result[ -], result[ -], result[ the] the ]; -}
The corresponding Java encryption algorithm
1 PackageCom.hiveview.phone.util;2 3 Importjava.security.MessageDigest;4 5 6 Public classMd5utils {7 8 Private Final StaticString[] hexdigits = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "B", "C", "D", "E", "F" };9 Ten One /** A - * Convert byte array to 16 binary string - the * - * @paramb - - * byte array + - * @return16 binary strings + A */ at - Public StaticString bytearraytohexstring (byte[] b) { - -StringBuffer RESULTSB =NewStringBuffer (); - - for(inti = 0; i < b.length; i++) in { - to resultsb.append (bytetohexstring (b[i)); + - } the * returnresultsb.tostring (); $ Panax Notoginseng } - the + Private StaticString bytetohexstring (byteb) { A the intn =b; + - if(N < 0) $ $n = 256 +N; - - intD1 = n/16; the - intD2 = n 16;Wuyi the returnHEXDIGITS[D1] +HEXDIGITS[D2]; - Wu } - About $ Public Staticstring Md5encode (String origin) { - -String resultstring =NULL; - A + Try { the -Resultstring =NewString (origin); $ theMessageDigest MD = messagedigest.getinstance ("MD5"); the theResultstring =bytearraytohexstring (Md.digest (Resultstring.getbytes ())); the -}Catch(Exception ex) { in the ex.printstacktrace (); the } About the returnresultstring; the the } + -}
iOS string MD5 Encrypted, returns the encrypted string