【发布时间】:2020-01-16 12:18:03
【问题描述】:
所以,PHP 代码:
$result = hash("whirlpool","xxx".$password."zzz");
JAVA:
import gnu.crypto.Registry;
import gnu.crypto.hash.HashFactory;
import gnu.crypto.hash.IMessageDigest;
public class WhirlpoolHash {
String result;
WhirlpoolHash(String pass) {
String to_encode = "xxx"+pass+"zzz";
IMessageDigest old_encoder = HashFactory.getInstance(Registry.WHIRLPOOL_HASH);
byte[] input = to_encode.getBytes();
old_encoder.update(input, 0, input.length);
byte[] digest = old_encoder.digest();
this.result = gnu.crypto.util.Util.toString(digest).toLowerCase();
}
public String Get() {
return this.result;
}
}
结果变量是不同的。我需要 java 类返回与 php 相同的值。 我将密码存储在 PHP 生成的 MySQL DB UTF-8 编码中,需要将其与 JavaFX 应用程序发送的数据进行比较。
当然,我可以发送未加密的密码,并使用 php 进行,但我不想这样做。
【问题讨论】:
-
我不是很熟悉,但是phps的hash过程可能和java使用的不一样。
-
不,它是一样的,它是 SHA256 @Maxim 看看这个问题,如果你有什么不明白的,请告诉我,stackoverflow.com/questions/4680661/…
-
Java 有一些不同的 Whirlpool 哈希库,但我认为 Whirlpool 是 С、Python 或 Java 中的 Whirlpool。我认为存在编码问题...
-
@KHI,所以我尝试了来自 java.nio.charset.StandardCharsets 的
to_encode.getBytes(StandardCharsets.UTF_8)并得到了与我没有重载 getBythes 方法的结果相同的结果。这很奇怪,因为我知道默认情况下 Java 中的所有字符串变量都保存在 UTF8 中,我用来发送传递给 PHP 脚本的 Jquery AJAX 默认情况下是 UTF8 两个。也许来自 Php 的盐是 ANCII?
标签: java php encryption hash whirlpool