Class PasswordSalt

    • Field Detail

      • DEFAULT_SALT_BYTES

        public static final int DEFAULT_SALT_BYTES
        Default salt byte length is nothing else is specified.
        See Also:
        Constant Field Values
    • Constructor Detail

      • PasswordSalt

        public PasswordSalt​(@Nonnull @Nonempty
                            byte[] aBytes)
        Constructor with salt bytes.
        Parameters:
        aBytes - Salt bytes to use. May not be null or empty.
    • Method Detail

      • getSaltBytes

        @Nonnull
        @Nonempty
        @ReturnsMutableCopy
        public byte[] getSaltBytes()
        Specified by:
        getSaltBytes in interface IPasswordSalt
        Returns:
        A copy of the pure salt bytes. Never null nor empty.
      • getSaltString

        @Nonnull
        @Nonempty
        public String getSaltString()
        Specified by:
        getSaltString in interface IPasswordSalt
        Returns:
        The salt bytes in a string representation for easy serialization. Never null nor empty.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • createRandom

        @Nonnull
        public static PasswordSalt createRandom()
        Returns:
        A new password salt with the default length of 32 and random bytes.
        Since:
        10.1.4
      • createRandom

        @Nonnull
        public static PasswordSalt createRandom​(@Nonnegative
                                                int nSaltBytes)
        Create a new password salt with the provided byte count.
        Parameters:
        nSaltBytes - The number of salt bytes to use. Must be > 0.
        Returns:
        the new salt object
        Since:
        10.1.4
      • createFromStringMaybe

        @Nullable
        public static PasswordSalt createFromStringMaybe​(@Nullable
                                                         String sSalt)
        Try to create a PasswordSalt object from the passed string. First the string is hex decoded into a byte array and this is the password salt.
        Parameters:
        sSalt - The string to be used. May be null.
        Returns:
        null if the passed salt string is null or empty.
        Throws:
        IllegalArgumentException - if the passed salt string cannot be hex decoded.