NSData+NTES.m 730 B

12345678910111213141516171819202122232425262728
  1. //
  2. // NSData+NTES.m
  3. // NIM
  4. //
  5. // Created by amao on 7/2/15.
  6. // Copyright (c) 2015 Netease. All rights reserved.
  7. //
  8. #import "NSData+NTES.h"
  9. #import <CommonCrypto/CommonDigest.h>
  10. @implementation NSData (NTES)
  11. - (NSString *)MD5String {
  12. const char *cstr = [self bytes];
  13. unsigned char result[16];
  14. CC_MD5(cstr, (CC_LONG)[self length], result);
  15. return [NSString stringWithFormat:
  16. @"%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],
  18. result[4], result[5], result[6], result[7],
  19. result[8], result[9], result[10], result[11],
  20. result[12], result[13], result[14], result[15]
  21. ];
  22. }
  23. @end