Java 的 MD5 哈希问题
如果我作为独立应用程序运行或在 Web 应用程序中运行,则 java 实现会为同一输入字符串创建两个不同的摘要。
独立应用程序与oracle dbms匹配 该实现是
MessageDigest md5 = MessageDigest.getInstance("MD5");
if (md5 != null) {
md5.reset();
newHashByte = md5.digest(msg.getBytes());
}
newHash = convertToString(newHashByte);
十六进制到字符串的转换实现,
StringBuffer result = new StringBuffer(64);
for (int i = 0; i < digestBits.length; i++)
hexDigit(result, digestBits[i]);
return result.toString();
如果您能帮助我们解决这个问题,我们将不胜感激。
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.
The standalone application matches with oracle dbms
The implementation is
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我怀疑你有不同的默认编码。像这样使用正确的编码,
I suspect you have different default encodings. Use the correct encoding like this,
在每种情况下,
msg
来自哪里?我认为在一种情况下,您的末尾可能有一个换行符,但在另一种情况下则没有。在这两种情况下,您的字符编码也可能以不同的方式设置。我非常怀疑您的示例中除了msg
之外的其他任何内容都在发生变化。Where does
msg
come from in each case? 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 exceptmsg
.