ネイティブiPhoneアプリケーションからC#サービスと通信しようとしています。パスワードを通信するには、入力したハッシュ値をサーバーに保存されているハッシュバージョンと比較する必要があります。私はObjective Cの中でC#のハッシュを再作成しようとしていますし、それはそれは面白いC#MD5とObjective Cの矛盾MD5
Objective Cのコードを取得するために始まるのです:
NSString * password = @"testPass123";
const char *cPassword = [password UTF8String];
NSString * key = @"Garbage12345";
NSData * keyData = [NSData dataFromBase64String:key];
NSUInteger len = [keyData length];
unsigned char * cKey = (unsigned char *)malloc(len);
memcpy(cKey, [keyData bytes], len);
// Concatenate into one byte array
unsigned char totalString[18];
for (int i = 0; i < strlen(cPassword); i++) {
totalString[i] = cPassword[i];
}
for (int i = 0; i < len; i++) {
totalString[strlen(cPassword) + i] = cKey[i];
}
// DEBUG: Display byte array
for (int i = 0; i < 18; i++) {
NSLog(@"totalString: %x", totalString[i]);
}
// **** totalString == plainTextWithSaltBytes from the C# portion ****
unsigned char result[CC_MD5_DIGEST_LENGTH];
CC_MD5(totalString, CC_MD5_DIGEST_LENGTH, result);
for (int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) {
NSLog(@"result: %02x", result[i]);
}
C#コード:
byte[] SaltBytes = Convert.FromBase64String("Garbage12345");
// Convert plain text into a byte array.
byte[] plainTextBytes = Encoding.UTF8.GetBytes("testPass123");
// Allocate array, which will hold plain text and salt.
byte[] plainTextWithSaltBytes = new byte[plainTextBytes.Length + SaltBytes.Length];
// Copy plain text bytes into resulting array.
for (int i = 0; i < plainTextBytes.Length; i++)
plainTextWithSaltBytes[i] = plainTextBytes[i];
// Append salt bytes to the resulting array.
for (int i = 0; i < SaltBytes.Length; i++)
plainTextWithSaltBytes[plainTextBytes.Length + i] = SaltBytes[i];
HashAlgorithm hash = new MD5CryptoServiceProvider();
// **** plainTextWithSaltBytes == totalString from the Obj-C portion ****
// Compute hash value of our plain text with appended salt.
byte[] hashBytes = hash.ComputeHash(plainTextWithSaltBytes);
// Convert result into a base64-encoded string.
string hashValue = Convert.ToBase64String(hashBytes);
を、私は戻って同じ結果を得ますバイト配列のMD5部分に入る前にバイト配列のために。提供されたダミーデータを使用して返されます:
74
65
73
74
50
61
73
73
31
32
33
19
aa
db
6a
07
b5
db
しかし、その後、私は別の値を返し、どこから行くのか分かりません。
誰もが考えている?私が間違っていることを指摘することは自由に感じてください。ありがとう。
サーバーへのハッシュの送信が安全でなく、パスワードを送信する方法について少し説明してください。攻撃者はどのようにハッシュを知るでしょうか?彼らがハッシュを知っていたとしても、どのようにそれらがログインすることができますか? –
攻撃者があなたのデータベースを侵害した場合、彼はすべてのユーザーのハッシュを知り、そのいずれかのユーザーとしてログインできます。パスワードを送信すると、ハッシュを元に戻さずにログインすることはできません。 – CodesInChaos
「ハッシュを知っていても、どのようにしてログインできますか?」通常のログインと同様にサーバーにハッシュを送信することでできますか?私は本当にあなたの質問を理解していない。 – CodesInChaos