add message exercises

This commit is contained in:
lianxiang
2018-08-23 18:09:15 +08:00
parent 3b8f57d02f
commit d43d7eaaf6
51 changed files with 1713 additions and 122 deletions
+14
View File
@@ -0,0 +1,14 @@
//
// NSString+MD5.h
// GIGA
//
// Created by lianxiang on 2018/8/23.
// Copyright © 2018年 com.giga.ios. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSString (MD5)
//MD5加密
- (NSString *)MD5;
@end
+30
View File
@@ -0,0 +1,30 @@
//
// 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