gpt4 book ai didi

iphone - 在 cocoa 中的字符串上使用 MD5 哈希?

转载 作者:IT老高 更新时间:2023-10-28 11:40:51 25 4
gpt4 key购买 nike

Possible Duplicate:
MD5 algorithm in Objective C

我需要在 cocoa 中使用 MD5 技术对字符串进行哈希处理。使用的任何框架都必须能够在 iphone 上访问。如果可能,请提供代码。

最佳答案

在 Facebook Connect 源代码中注意到了这一点。看起来很结实,试一试。

#import <CommonCrypto/CommonDigest.h>

...

+ (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*2];
for(int i = 0; i<CC_MD5_DIGEST_LENGTH; i++) {
[ret appendFormat:@"%02x",result[i]];
}
return ret;
}
...

关于iphone - 在 cocoa 中的字符串上使用 MD5 哈希?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/652300/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com