Class PasswordSecret

  • All Implemented Interfaces:
    java.lang.Cloneable

    public class PasswordSecret
    extends SharedSecret
    A secret password used for authentication.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int MIN_GOOD_PASSWORD_LENGTH
      Password length weakness threshold.
      protected java.lang.String password
      The password.
      static java.lang.String PREFIX
      Prefix used to encode secret type as strings.
      protected static int SCRYPT_N
      SCrypt work factor / hardness for password strengthening.
      protected static int SCRYPT_P
      SCrypt parallelization.
      protected static int SCRYPT_R
      SCrypt block size.
    • Constructor Summary

      Constructors 
      Constructor Description
      PasswordSecret()
      Creates the secret.
      PasswordSecret​(java.lang.String encodedpassword)
      Creates the secret.
      PasswordSecret​(java.lang.String password, boolean encoded)
      Creates the secret.
    • Field Detail

      • MIN_GOOD_PASSWORD_LENGTH

        public static final int MIN_GOOD_PASSWORD_LENGTH
        Password length weakness threshold.
        See Also:
        Constant Field Values
      • PREFIX

        public static final java.lang.String PREFIX
        Prefix used to encode secret type as strings.
        See Also:
        Constant Field Values
      • SCRYPT_N

        protected static final int SCRYPT_N
        SCrypt work factor / hardness for password strengthening.
        See Also:
        Constant Field Values
      • password

        protected java.lang.String password
        The password.
    • Constructor Detail

      • PasswordSecret

        public PasswordSecret()
        Creates the secret.
      • PasswordSecret

        public PasswordSecret​(java.lang.String encodedpassword)
        Creates the secret.
      • PasswordSecret

        public PasswordSecret​(java.lang.String password,
                              boolean encoded)
        Creates the secret.
    • Method Detail

      • getPassword

        public java.lang.String getPassword()
        Gets the password.
        Returns:
        The password.
      • setPassword

        public void setPassword​(java.lang.String password)
        Sets the password.
        Parameters:
        password - The password.
      • getKdfParams

        public byte[] getKdfParams()
        Gets the key derivation parameters.
        Returns:
        Key derivation parameters.
      • deriveKey

        public byte[] deriveKey​(int keysize,
                                byte[] salt)
        Derives a key from the password with appropriate hardening.
        Specified by:
        deriveKey in class SharedSecret
        Parameters:
        keysize - The target key size in bytes to generate.
        salt - Salt to use.
        Returns:
        Derived key.
      • deriveKey

        public byte[] deriveKey​(int keysize,
                                byte[] salt,
                                byte[] dfparams)
        Derives a key from the password with appropriate hardening.
        Parameters:
        keysize - The target key size in bytes to generate.
        salt - Salt to use.
        dfparams - Key derivation parameters.
        Returns:
        Derived key.
      • isWeak

        public boolean isWeak()
        Returns if the password is weak.
        Returns:
        True, if weak.
      • toString

        public java.lang.String toString()
        Creates encoded secret.
        Overrides:
        toString in class java.lang.Object
        Returns:
        Encoded secret.
      • main

        public static void main​(java.lang.String[] args)