Home > Blockchain >  Caused by: java.lang.IllegalArgumentException: Invalid salt revision
Caused by: java.lang.IllegalArgumentException: Invalid salt revision

Time:05-19

i have create an university project with Java And Symfony when the user register from my java app he can login with both java and symfony , but the contrary it is impossible , it only login from symfony and it display to me this error in java

Caused by: java.lang.IllegalArgumentException: Invalid salt revision

Cryptage Methode : Bcrypt Security.yml Symf

        App\Entity\Utilisateur: 
        algorithm: bcrypt
        encode_as_base64: false
        iterations: 1

Utilisateur entity

 /**
 * Returning a salt is only needed, if you are not using a modern
 * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
 *
 * @see UserInterface
 */
public function getSalt(): ?string
{
    return null;
}

JAVA

Login Method

 if (rs.getString("email").equals(t.getEmail()) && BCrypt.checkpw(t.getMotpasse(), rs.getString("motpasse")) == true) {
                    if (rs.getString("activated").equals("Active")) {
                        idUser = rs.getInt("idU");

CodePudding user response:

For more information on this error check BCrypt.checkpw() Invalid salt version exception

I would suggest you start to debug the following piece of your code:

BCrypt.checkpw(t.getMotpasse(), rs.getString("motpasse"))

Check in your database what the value for the hashed password is. Does it match the expected value of $xy$... where xy should be 2a, 2b, 2y or similar.

Check in your Java code what the values of password t.getMotpasse() and hashed password rs.getString("motpasse") are; log them/debug the code.

Make sure to check the documentation, that you are providing the arguments of checkpw in the correct order (plain, hashed and not hashed, plain).

But I suspect that your PHP library generates a newer salt version (revision) that your current java library does not support. See for example https://github.com/djmdjm/jBCrypt/issues/2

Some code examples that i could find throw this exception when the salt version is not 2a, which would explain why generated salts from Java do work, but from Php don't.

In that case you will either have to:

  • make sure the PHP code generates salt versions 2a
  • upgrade/change the Java BCrypt library to a version that supports the newer salt revision
  • Related