NSString+XHMD5.m 831 B

123456789101112131415161718192021222324252627
  1. //
  2. // NSString+XHMD5.m
  3. // XHImageViewer
  4. //
  5. // Created by 曾 宪华 on 14-2-18.
  6. // Copyright (c) 2014年 曾宪华 开发团队(http://iyilunba.com ) 本人QQ:543413507 本人QQ群(142557668). All rights reserved.
  7. //
  8. #import "NSString+XHMD5.h"
  9. #import <CommonCrypto/CommonCrypto.h>
  10. @implementation NSString (XHMD5)
  11. - (NSString *)MD5Hash {
  12. if(self.length == 0) { return nil; }
  13. const char *cStr = [self UTF8String];
  14. unsigned char result[16];
  15. CC_MD5(cStr, (CC_LONG)strlen(cStr), result);
  16. return [NSString stringWithFormat:@"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
  17. result[0], result[1], result[2], result[3], result[4], result[5], result[6], result[7],
  18. result[8], result[9], result[10], result[11],result[12], result[13], result[14], result[15]];
  19. }
  20. @end