暂无描述

KXMD5Manager.m 938B

1234567891011121314151617181920212223242526272829303132333435363738
  1. //
  2. // KXMD5Manager.m
  3. // CAISHEN
  4. //
  5. // Created by jikaipeng on 2017/9/27.
  6. // Copyright © 2017年 kuxuan. All rights reserved.
  7. //
  8. #import "KXMD5Manager.h"
  9. #import <CommonCrypto/CommonDigest.h>
  10. @implementation KXMD5Manager
  11. + (instancetype)sharedInstance{
  12. static KXMD5Manager *md5Manager = nil;
  13. static dispatch_once_t onceToken;
  14. dispatch_once(&onceToken, ^{
  15. if (md5Manager == nil) {
  16. md5Manager = [[KXMD5Manager alloc] init];
  17. }
  18. });
  19. return md5Manager;
  20. }
  21. - (NSString *) md5:(NSString *) input {
  22. const char *cStr = [input UTF8String];
  23. unsigned char digest[CC_MD5_DIGEST_LENGTH];
  24. CC_MD5( cStr, strlen(cStr), digest ); // This is the md5 call
  25. NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
  26. for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
  27. [output appendFormat:@"%02x", digest[i]];
  28. return output;
  29. }
  30. @end