+ (NSString*)md5Codesign:(NSDictionary*)dict{
NSArray*allKeyArray = [dictallKeys];
NSArray*afterSortKeyArray = [allKeyArray sortedArrayUsingComparator:^NSComparisonResult(id _Nonnullobj1,id _Nonnullobj2) {
NSComparisonResultresuest = [obj1compare:obj2];
return resuest;
}];
//NSLog(@"afterSortKeyArray:%@",afterSortKeyArray);
//通过排列的key值获取value
NSMutableArray *valueArray = [NSMutableArray array];
for(NSString*sortsing in afterSortKeyArray) {
NSString*valueString = [dictobjectForKey:sortsing];
[valueArray addObject:valueString];
}
NSMutableString *signString = [NSMutableString string];
for(inti =0; i < afterSortKeyArray.count; i++) {
NSString*keyValue = [NSString stringWithFormat:@"%@",valueArray[i]];
[signString appendString:keyValue];
}
//signString用于签名的原始参数集合
// MYLog(@"%@",signString);
// MYLog(@"%@",[signString md5Str]);
return [signString md5Str];
}
-(NSString*)md5Str
{
const char* myPasswordd = [selfUTF8String];
unsigned char md5c[16];
CC_MD5(myPasswordd, (CC_LONG)strlen(myPasswordd), md5c);
NSMutableString *md5Str = [NSMutableString string];
for(inti =0; i<16; i++) {
[md5Str appendFormat:@"%02x",md5c[i]];
}
return md5Str;
}
网友评论