Class EncodedPassword


  • public final class EncodedPassword
    extends Object
    Encoded password representation.

    Helps with parsing strings in the form of {Base64(salt)}password-hash into a value object, like

     EncodedPassword password = new EncodedPassword("{VGhlU2FsdA==}1L/qmnQ8kbgckAodOCbtyJAhoiK4k0rBtBBN+WD+TIE=");
     System.out.println(password.salt + " " + password.password);
     
    • Field Detail

      • salt

        public byte[] salt
        The salt used for hashing the password or null if no salt is used.
      • password

        public String password
        The password hash if this object has been created from an encoded password or the clear text password to be encoded.
    • Constructor Detail

      • EncodedPassword

        public EncodedPassword​(String formattedPassword)
        Creates an instance from the {Base64(salt)}password-hash formatted String.
        Parameters:
        formattedPassword - Password hash in the {Base64(salt)}password-hash format
    • Method Detail

      • fromHonoSecret

        public static EncodedPassword fromHonoSecret​(io.vertx.core.json.JsonObject secret)
                                              throws IllegalArgumentException
        Creates a new instance from Hono Secret.

        The secret is expected to be of type hashed-password as defined by Hono's Credentials API.

        Parameters:
        secret - JSON object that contains the Hono-formatted secret.
        Returns:
        The password value object.
        Throws:
        NullPointerException - if secret is null.
        IllegalArgumentException - if the secret does not contain a password hash or if the salt is not valid Base64 schema.
      • format

        public String format()
        Creates a string representation of this password that is compatible with Spring Security password encoders.
        Returns:
        The value of this object formatted as {Base64(salt)}password.