Java如何做sha256哈希等价于php密码函数?结果不一样


Java how to do sha256 hashing equiavelent to php crypt function ? result is not the same?

我正在使用http://raginggoblin.wordpress.com/2012/08/11/java-alternative-to-php-crypt-function/对于php crypt函数的等价物,或者它在这里说它是…

但我在java和php中有相同的值,但哈希结果不同。。我想知道不哈希是否因为执行方式不同而有所不同?我将这两个值发布到WS-

JAVA:

 String doc_data="{'"table'":'"1048582'"}";
 String data="$5$rounds=5000$503$La071hYxZERff9GGq0cb.x2k96Xx25'/C4vxQztQ7B96";
 String result=Crypt.crypt(doc_data, data);
PHP: 
 $params['result'] = crypt($params['doc_data'], @$this->initdata['data']);

我记录了它,并从POST中输入了确切的数据。。。但是结果不一样。。没有办法做到这一点,对吗?或者没有等价物?

在那个图书馆之前,我用的是番石榴。。但仍然不是相同的

public static String crypt_sha256(String password, String salt) {
        int iteration_count = 5000;
        HashFunction func = Hashing.sha256();
        HashCode result = func.hashString(salt + param1, Charsets.UTF_8);
        for (int i = 0; i < iteration_count; i++) {
            result = func.hashBytes(result.asBytes());
        }
        return salt + result.toString();
}

Oke,到目前为止,我测试了一些库的,获胜者是Apache的Crypt。http://commons.apache.org/proper/commons-codec/apidocs/org/apache/commons/codec/digest/Crypt.html

public static String crpyt_sha256_apache(String param1, String salt) {
        return Crypt.crypt(param1, salt);
    }