我的练习是将管理后端
从 php 移植到 .net。
后端与用java编写的应用程序通信。
与 md5 哈希值相比,在 php 和 java 中,md5 哈希值是相同的。
我无法更改 java 应用程序中的 md5 哈希码,因为这样一来超过 10k 的客户卡将无法工作。
我的问题是,后端已移植,现在新后端(.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
生成 MD5 哈希,而不是 bb27aee4
因此请检查代码中的错误
祝你好运
关于C# MD5 哈希与 Java/PHP MD5 哈希不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22906588/