iOS 关于MD5容易遗漏的两个库

来源:互联网 发布:lg d2341软件 编辑:程序博客网 时间:2024/06/05 01:13

iOS中MD5加密

iOS MD5


  1. + (NSString *)MD5:(NSString *)str
  2. {
  3. const char *cStr = [str UTF8String];
  4. unsigned char result[16];
  5. CC_MD5(cStr, strlen(cStr), result); // This is the md5 call
  6. return [NSString stringWithFormat:
  7. @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
  8. result[0], result[1], result[2], result[3],
  9. result[4], result[5], result[6], result[7],
  10. result[8], result[9], result[10], result[11],
  11. result[12], result[13], result[14], result[15]
  12. ];
  13. }

代码很少 , 但是需要有两个库的支持

  1. #import <CommonCrypto/CommonDigest.h>
  2. #import <CoreText/CoreText.h>
0 0