带有哈希的NSString MD5 [英] NSString MD5 with hash
本文介绍了带有哈希的NSString MD5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好必须通过网络服务执行登录,并发送用户名和密码。
问题是服务器希望使用奇怪的MD5格式的密码,而我无法生成该密码。
Hi have to perform a login via web service sending username and password. The problem is that the server wants a strange MD5 format of password and I can't generate it.
示例
NSString password = @".";
NSString md5 = @"5058f1af8388633f609cadb75a75dc9d";
服务器MD5是PXñ¯c?`–·ZuÜ 。
我需要转换 PXñ¯ˆc?`–·ZuÜ 中的 5058f1af8388633f609cadb75a75dc9d ,但我没有
I need to transform 5058f1af8388633f609cadb75a75dc9d in "PXñ¯ƒˆc?`œ·ZuÜ", but I have no ideas.
编辑
我发现结果是哈希值 5058f1af8388633f609cadb75a75dc9d 字符串的形式。这是服务器上的 .NET
代码:
I've discovered that the result is an hash of 5058f1af8388633f609cadb75a75dc9d string.This is the .NET
code on server:
byte[] passwordBytesEnc = UTF8Encoding.Default.GetBytes(".");
byte[] passwordBytesHash = MD5.Create().ComputeHash(passwordBytesEnc);
string passwordCriptata = UTF8Encoding.Default.GetString(passwordBytesHash);
推荐答案
尝试一下。.
- (NSString *)MD5String:(NSString *)string{
const char *cstr = [string UTF8String];
NSLog(@"%s",cstr);
unsigned char result[16];
CC_MD5(cstr, strlen(cstr), result);
NSLog(@"%s",result);
return [NSString stringWithFormat:
@"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
result[0], result[1], result[2], result[3],
result[4], result[5], result[6], result[7],
result[8], result[9], result[10], result[11],
result[12], result[13], result[14], result[15]
];
}
并像这样呼叫
NSString *md5 = @"5058f1af8388633f609cadb75a75dc9d";
[self MD5String:md5];
这篇关于带有哈希的NSString MD5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文