2014-06-29 46 views
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。

+0

我对此并不是很熟悉,但是phps散列过程可能与java所使用的不同。 –

+0

不,它是相同的,这是SHA256 @Maxim掠过这个伫立,并让我知道如果你什么都不明白,http://stackoverflow.com/questions/4680661/java-sha256-outputs-different-哈希到php-sha256 –

+0

Java有一些Whirlpool散列的不同库,但我认为Whirlpool是С,Python或Java中的Whirlpool。我认为有一个编码问题... –

回答