美文网首页
iOS请求参数按key排序再MD5加密

iOS请求参数按key排序再MD5加密

作者: 我是小志 | 来源:发表于2018-06-29 15:21 被阅读0次

    + (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;

    }

    相关文章

      网友评论

          本文标题:iOS请求参数按key排序再MD5加密

          本文链接:https://www.haomeiwen.com/subject/weimhttx.html