Question: PHP sha256 hash different than Java Guava one
I'm trying to validate sha256 hashes generated via Java Guava Hashing class using PHP, but can't seem to do it. I can't touch Java files, so fix has to be done on java error PHP side. Both PHP and Java use UTF-8 encoding. What am I missing?
Java:
package org.test.hash; import com.google.common.hash.Hashing; public class Main { public static void main(String[] args) throws Exception { String salt = "0123456789012345"; String password = "password"; System.out.println( Hashing.sha256().hashUnencodedChars(salt + "|" + password).toString() ); } }
Output:
818112d34d341ace8b9325fce61e676a125f733e25c28c9ed172c1f7d2c3aa6c
PHP:
$salt = "0123456789012345"; $password = "password"; print_r(hash("sha256", $salt . "|" . $password));
Output:
1f0a70940ae365e930c51e3de4c0a82f853f7663fc17acd36406982666685703
9codings