Witam kolegów !
Jestem początkującym programistą, mam problem z generowaniem skrótu za pomocą MD5 w C#.
Posiadam funkcję hashującą stringa:
private static string MD5Hash(string input)
{
StringBuilder hash = new StringBuilder();
MD5 md5 = MD5.Create();
byte[] inputbytes = System.Text.Encoding.ASCII.GetBytes(input);
byte[] hashbytes = md5.ComputeHash(inputbytes);
for (int i = 0; i < hashbytes.Length; i++)
{
hash.Append(hashbytes[i].ToString("x2"));
}
return hash.ToString();
}
wywołując powyższą funkcję z argumentem "aaa" otrzymuję e6a97266e55eb41d155087dc21601507
Mam inną aplikację pisaną w C++ framework QT która również posiada funkcję hashującą.
wynik dla stringa "aaa" to 47bce5c74f589f4867dbd57e9ca9f808 (generatory na stronach www generują właśnie taki skrót, wnioskuję z tego że poniższy kod robi to poprawnie)
QCryptographicHash hasloszyfr(QCryptographicHash::Md5);
hasloszyfr.reset();
hasloszyfr.addData(nowe_haslo.toLatin1());
QString zaszyfrowanehaslo=hasloszyfr.result().toHex();
Problem polega na tym że obie aplikacje mają korzystać z tej samej bazy a generują różne hashe dla tych samych stringów.