我的练习是将administration-backend
从php移植到.net。
后端与用Java编写的应用程序进行通信。
与md5-哈希相比,有些东西在php和java中md5哈希是同等的。
我无法在Java应用程序中更改md5哈希码,因为这样一来,超过1万张客户卡将无法使用。
我的问题是,后端已移植,现在新后端(.net)与Java应用程序之间进行了通信。
我的.net md5-hash代码返回的哈希值与Java代码不同。
Java的:
public static String getMD5(String input) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] messageDigest = md.digest(input.getBytes());
BigInteger number = new BigInteger(1, messageDigest);
String hashtext = number.toString(16);
// Now we need to zero pad it if you actually want the full 32 chars.
while (hashtext.length() < 32)
hashtext = "0" + hashtext;
return hashtext;
}
catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
和我的.net代码:
public String hashMD5(String wert)
{
byte[] asciiBytes = ASCIIEncoding.UTF8.GetBytes(wert);
byte[] hashedBytes = MD5CryptoServiceProvider.Create().ComputeHash(asciiBytes);
string hashedString = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
return hashedString;
}
我的Java代码返回
bb27aee4
:46d5acfcd281bca9f1df7c9e38d50576
我的.net代码返回:
b767fe33172ec6cbea569810ee6cfc05
我不知道该怎么办...
请帮助并提前致谢。
最佳答案
它不是MD5哈希生成器的问题bb27aee4
的MD5哈希:46d5acfcd281bca9f1df7c9e38d50576
&BB27AEE4
的MD5哈希:b767fe33172ec6cbea569810ee6cfc05
因此,基本上在.NET中,您正在为BB27AEE4
而不是bb27aee4
生成MD5哈希
因此,请检查代码中的错误
祝好运