0

Java で作成された私のアプリケーションは、Whirlpool を使用してパスワードをハッシュします。次に、PHP で同じ方法を使用する必要があります。これは私が Java で作成したコードです。

private String getPasswordHash(String user, String password)
{
    String salt = "M0z3ah4SKieNwBboZ94URhIdDbgTNT";
    String user_lowercase = user.toLowerCase();

    // mix the user with the salt to create a unique salt
    String uniqueSalt = "";
    for(int i = 0; i < user_lowercase.length(); i++)
    {
        uniqueSalt += user_lowercase.substring(i, i + 1) + salt.substring(i, i + 1);
        // last iteration, add remaining salt to the end
        if(i == user_lowercase.length() - 1)
            uniqueSalt += salt.substring(i + 1);
    }

    Whirlpool hasher = new Whirlpool();
    hasher.NESSIEinit();

    // add plaintext password with salt to hasher
    hasher.NESSIEadd(password + uniqueSalt);

    // create array to hold the hashed bytes
    byte[] hashed = new byte[64];

    // run the hash
    hasher.NESSIEfinalize(hashed);

    // turn the byte array into a hexstring
    char[] val = new char[2 * hashed.length];
    String hex = "0123456789ABCDEF";
    for(int i = 0; i < hashed.length; i++)
    {
        int b = hashed[i] & 0xff;
        val[2 * i] = hex.charAt(b >>> 4);
        val[2 * i + 1] = hex.charAt(b & 15);
    }
    return String.valueOf(val);
}

しかし、今度はこのコードを PHP に「変換」する必要があります。これは私がやろうとしたことですが、私は PHP を使用する専門家ではありません。

$salt = "M0z3ah4SKieNwBboZ94URhIdDbgTNT";
$user = "Speedys";
$password = "test123";

//This is what the final result should look like:
$result = "8BD01A206E7B5378B00F77A0E3C5C39B7011CCF87F5BE132F495A77F418E0743C6CB514D53EF01CD4A2C170013C8B9C76E03D9CC94BA404983375CBC3E67E703";

$user_lowercase = strtolower($user);

$uniqueSalt = "";

        for($i = 0; $i < strlen($user_lowercase); $i++)
        {
            $uniqueSalt .= substr($user_lowercase, $i, $i + 1) . substr($salt, $i, $i + 1);
            // last iteration, add remaining salt to the end
            if($i == strlen($user_lowercase) - 1)
                $uniqueSalt .= substr($salt, $i + 1);
        }

$hash = hash( 'whirlpool', $password.$uniqueSalt );

しかし、私は同じ結果を得ません。手伝っていただけませんか?

編集:これは、実際のphpコードで得た結果です:

459897235ff5811026a5393e6ae58706bb99783d62bd58b41f6ca82d978aa17eaccbef95d383f1ac9d68f93f5ba68ef2005c6b467c0fa81977566a708d98e220

これは私がJavaで得た結果であり、私が望むものです:

8BD01A206E7B5378B00F77A0E3C5C39B7011CCF87F5BE132F495A77F418E0743C6CB514D53EF01CD4A2C170013C8B9C76E03D9CC94BA404983375CBC3E67E703
4

0 に答える 0