-
MD5 iOS代码加密
创建MD5类,代码如下
#import <Foundation/Foundation.h>
@interface CJMD5 : NSObject
+(NSString *)md5HexDigest:(NSString *)input;
@end
-
#import "CJMD5.h"
#import <CommonCrypto/CommonDigest.h>
@implementation CJMD5
+(NSString *)md5HexDigest:(NSString *)input{
const char* str = [input UTF8String];
unsigned char result[CC_MD5_DIGEST_LENGTH];
CC_MD5(str, strlen(str), result);
NSMutableString *ret = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH];
for(int i = 0; i<CC_MD5_DIGEST_LENGTH; i++) {
[ret appendFormat:@"%02X",result];
}
return ret;
}
@end
-
MD5是不可逆的只有加密没有解密,iOS代码加密使用方式如下
NSString *userName = @"cerastes";
NSString *password = @"hello Word";
// MD5加密
NSString *md5 = [CJMD5 md5HexDigest:password];
NSLog(@"%@",md5);
END