Keine Beschreibung

NSString+ASString.m 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //
  2. // NSString+ASString.m
  3. // ACSION
  4. //
  5. // Created by sunyue on 2019/4/22.
  6. // Copyright © 2019 acsion. All rights reserved.
  7. //
  8. #import "NSString+ASString.h"
  9. #import <CommonCrypto/CommonDigest.h>
  10. @implementation NSString (ASString)
  11. - (instancetype)md5 {
  12. const char *cStr = [self UTF8String];
  13. unsigned char digest[CC_MD5_DIGEST_LENGTH];
  14. CC_MD5( cStr, strlen(cStr), digest ); // This is the md5 call
  15. NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
  16. for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
  17. [output appendFormat:@"%02x", digest[i]];
  18. return output;
  19. }
  20. - (instancetype)otherMd5 {
  21. const char *cStr = [self UTF8String];
  22. unsigned char result [CC_MD5_DIGEST_LENGTH];
  23. CC_MD5( cStr, (CC_LONG)strlen(cStr), result );
  24. return [NSString stringWithFormat: @"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
  25. result[0], result[1],
  26. result[2], result[3],
  27. result[4], result[5],
  28. result[6], result[7],
  29. result[8], result[9],
  30. result[10], result[11],
  31. result[12], result[13],
  32. result[14], result[15]
  33. ];
  34. }
  35. @end