[英]MD5 Hash Issue with Java
A java implementation creates two different digest for a same input string, if i run as stand alone application or running inside a web application. 如果我作为独立应用程序运行或在Web应用程序内部运行,则Java实现会为同一输入字符串创建两个不同的摘要。
The standalone application matches with oracle dbms The implementation is 独立应用程序与oracle dbms匹配实现是
MessageDigest md5 = MessageDigest.getInstance("MD5");
if (md5 != null) {
md5.reset();
newHashByte = md5.digest(msg.getBytes());
}
newHash = convertToString(newHashByte);
Hex to String conversion implementation is 十六进制到字符串的转换实现是
StringBuffer result = new StringBuffer(64);
for (int i = 0; i < digestBits.length; i++)
hexDigit(result, digestBits[i]);
return result.toString();
Highly appreciate if you could help us resolving this. 非常感谢您能帮助我们解决这个问题。
I suspect you have different default encodings. 我怀疑您有不同的默认编码。 Use the correct encoding like this, 这样使用正确的编码,
newHashByte = md5.digest(msg.getBytes("utf-8"));
Where does msg
come from in each case? msg
来自哪里? I think it's likely you have a newline character on the end in one case but not the other. 我认为在一种情况下,您最后可能会有换行符,但在另一种情况下,您可能没有。 It's also possible that your character encodings are set differently somehow in the two scenarios. 在两种情况下,字符编码的设置也可能有所不同。 I highly doubt that anything else in your example is changing except msg
. 我非常怀疑您的示例中除msg
之外的其他任何更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.