31 lines
715 B
Objective-C
31 lines
715 B
Objective-C
//
|
|
// NSString+MD5.m
|
|
// GIGA
|
|
//
|
|
// Created by lianxiang on 2018/8/23.
|
|
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
|
//
|
|
|
|
#import "NSString+MD5.h"
|
|
#import <CommonCrypto/CommonDigest.h>
|
|
@implementation NSString (MD5)
|
|
//MD5加密
|
|
- (NSString *)MD5{
|
|
|
|
const char *ptr = [self UTF8String];
|
|
|
|
unsigned char md5Buffer[CC_MD5_DIGEST_LENGTH];
|
|
|
|
CC_MD5(ptr, (unsigned int)strlen(ptr), md5Buffer);
|
|
|
|
NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH *2];
|
|
for (int i = 0; i<CC_MD5_DIGEST_LENGTH; i++) {
|
|
[output appendFormat:@"%02x",md5Buffer[i]];
|
|
}
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
@end
|