0
所以,PHP代碼:Java和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做,但我不想whant。
我對此並不是很熟悉,但是phps散列過程可能與java所使用的不同。 –
不,它是相同的,這是SHA256 @Maxim掠過這個佇立,並讓我知道如果你什麼都不明白,http://stackoverflow.com/questions/4680661/java-sha256-outputs-different-哈希到php-sha256 –
Java有一些Whirlpool散列的不同庫,但我認爲Whirlpool是С,Python或Java中的Whirlpool。我認爲有一個編碼問題... –