暫無描述

NSString+MD5.m 754B

1234567891011121314151617181920212223242526272829
  1. //
  2. // Created by Nigel Timothy Barber (@mindbrix) on 13/04/2012.
  3. //
  4. #import "NSString+MD5.h"
  5. #import <CommonCrypto/CommonDigest.h>
  6. /* From: https://gist.github.com/1209911
  7. */
  8. @implementation NSString(MD5)
  9. - (NSString*)MD5
  10. {
  11. const char *cStr = [self UTF8String];
  12. unsigned char result[16];
  13. CC_MD5( cStr, (CC_LONG)strlen(cStr), result ); // This is the md5 call
  14. return [NSString stringWithFormat:
  15. @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
  16. result[0], result[1], result[2], result[3],
  17. result[4], result[5], result[6], result[7],
  18. result[8], result[9], result[10], result[11],
  19. result[12], result[13], result[14], result[15]
  20. ];
  21. }
  22. @end