我正在尝试从一个字符串生成MD5。我成功地生成了密钥,但问题是我的密钥与android密钥不同。我使用一个在线工具生成了MD5密钥,其结果与android相同,但与我的密钥不匹配。我使用静态字符串生成MD5,它是
1418212369896Sph!nxRock
android MD5 key > d3db2cd07e21b3b55330d6746de32c0d (这与在线工具完全类似)
IOS MD5键> 2EC05E18061E51D326BF0BA7889B5413
我用来生成MD5的代码如下
发布于 2014-12-10 13:22:25
我用过这样的方法:
NSString+MD5.h
#import <Foundation/Foundation.h>
@interface NSString (MD5)
- (NSString *)MD5;
@endNSString+MD5.m
#import "NSString+MD5.h"
#import <CommonCrypto/CommonDigest.h>
@implementation NSString (MD5)
- (NSString *)MD5 {
const char * pointer = [self UTF8String];
unsigned char md5Buffer[CC_MD5_DIGEST_LENGTH];
CC_MD5(pointer, (CC_LONG)strlen(pointer), md5Buffer);
NSMutableString *string = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
for (int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
[string appendFormat:@"%02x",md5Buffer[i]];
return string;
}
@end用于字符串:1418212369896Sph!nxRock
您的在线服务的结果是:d3db2cd07e21b3b55330d6746de32c0d
方法返回:d3db2cd07e21b3b55330d6746de32c0d
希望这能帮到你
https://stackoverflow.com/questions/27400983
复制相似问题