Class SCryptPassword.Encoder

java.lang.Object
io.inverno.mod.security.authentication.password.SCryptPassword.Encoder
All Implemented Interfaces:
Password.Encoder<SCryptPassword,SCryptPassword.Encoder>
Enclosing class:
SCryptPassword

public static class SCryptPassword.Encoder extends Object implements Password.Encoder<SCryptPassword,SCryptPassword.Encoder>

A Scrypt password encoder implementation.

Since:
1.5
Author:
Jeremy Kuhn
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The default block size factor: 8.
    static final int
    The default cost factor as power of two: 2^14.
    static final int
    The default hash length in kikibytes: 32.
    static final int
    The default parallelization factor: 1.
    static final int
    The default salt length in kikibytes: 16.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a default Scrypt password encoder.
    Encoder(int saltLength, int costFactor, int blockSizeFactor, int parallelizationFactor, int hashLength)
    Creates a default Scrypt password encoder with the specified salt length, cost factor, block size factor, parallelization factor and hash length.
    Encoder(int saltLength, int costFactor, int blockSizeFactor, int parallelizationFactor, int hashLength, SecureRandom secureRandom)
    Creates a default Scrypt password encoder with the specified salt length, cost factor, block size factor, parallelization factor, hash length and secure random.
  • Method Summary

    Modifier and Type
    Method
    Description
    Encodes the specified raw password.
    boolean
     
    int
    Returns the block size factor.
    int
    Returns the cost factor.
    int
    Returns the hash length in kikibytes.
    int
    Returns the parallelization factor.
    int
    Returns the salt length in kikibytes.
    Returns the secure random.
    int
     
    boolean
    matches(String raw, String encoded)
    Matches the specified raw password with the specified encoded representation.
    recover(String encoded)
    Recovers a password from its encoded representation generated with this encoder.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.inverno.mod.security.authentication.password.Password.Encoder

    matches
  • Field Details

    • DEFAULT_SALT_LENGTH

      public static final int DEFAULT_SALT_LENGTH
      The default salt length in kikibytes: 16.
      See Also:
    • DEFAULT_COST_FACTOR

      public static final int DEFAULT_COST_FACTOR
      The default cost factor as power of two: 2^14.
      See Also:
    • DEFAULT_BLOCK_SIZE_FACTOR

      public static final int DEFAULT_BLOCK_SIZE_FACTOR
      The default block size factor: 8.
      See Also:
    • DEFAULT_PARALLELIZATION_FACTOR

      public static final int DEFAULT_PARALLELIZATION_FACTOR
      The default parallelization factor: 1.
      See Also:
    • DEFAULT_HASH_LENGTH

      public static final int DEFAULT_HASH_LENGTH
      The default hash length in kikibytes: 32.
      See Also:
  • Constructor Details

    • Encoder

      public Encoder()

      Creates a default Scrypt password encoder.

    • Encoder

      public Encoder(int saltLength, int costFactor, int blockSizeFactor, int parallelizationFactor, int hashLength) throws IllegalArgumentException

      Creates a default Scrypt password encoder with the specified salt length, cost factor, block size factor, parallelization factor and hash length.

      Parameters:
      saltLength - the salt length in kikibytes
      costFactor - the cost factor
      blockSizeFactor - the block size factor
      parallelizationFactor - the parallelization factor
      hashLength - the hash length in kikibytes
      Throws:
      IllegalArgumentException - if specified parameters are incorrect
    • Encoder

      public Encoder(int saltLength, int costFactor, int blockSizeFactor, int parallelizationFactor, int hashLength, SecureRandom secureRandom) throws IllegalArgumentException

      Creates a default Scrypt password encoder with the specified salt length, cost factor, block size factor, parallelization factor, hash length and secure random.

      Parameters:
      saltLength - the salt length in kikibytes
      costFactor - the cost factor
      blockSizeFactor - the block size factor
      parallelizationFactor - the parallelization factor
      hashLength - the hash length in kikibytes
      secureRandom - the secure random
      Throws:
      IllegalArgumentException - if specified parameters are incorrect
  • Method Details

    • getSaltLength

      public int getSaltLength()

      Returns the salt length in kikibytes.

      Returns:
      the salt length
    • getCostFactor

      public int getCostFactor()

      Returns the cost factor.

      Returns:
      the cost factor.
    • getBlockSizeFactor

      public int getBlockSizeFactor()

      Returns the block size factor.

      Returns:
      the block size factor
    • getParallelizationFactor

      public int getParallelizationFactor()

      Returns the parallelization factor.

      Returns:
      the parallelization factor
    • getHashLength

      public int getHashLength()

      Returns the hash length in kikibytes.

      Returns:
      the hash length
    • getSecureRandom

      public SecureRandom getSecureRandom()

      Returns the secure random.

      Returns:
      the secure random
    • recover

      public SCryptPassword recover(String encoded) throws PasswordException
      Description copied from interface: Password.Encoder

      Recovers a password from its encoded representation generated with this encoder.

      Specified by:
      recover in interface Password.Encoder<SCryptPassword,SCryptPassword.Encoder>
      Parameters:
      encoded - an encoded password representation
      Returns:
      a password
      Throws:
      PasswordException - if there was an error recovering the password or if the specified encoded representation was not generated with this encoder
    • encode

      public SCryptPassword encode(String raw) throws PasswordException
      Description copied from interface: Password.Encoder

      Encodes the specified raw password.

      Specified by:
      encode in interface Password.Encoder<SCryptPassword,SCryptPassword.Encoder>
      Parameters:
      raw - a raw password
      Returns:
      an encoded password
      Throws:
      PasswordException - if there was an error encoding the password
    • matches

      public boolean matches(String raw, String encoded) throws PasswordException
      Description copied from interface: Password.Encoder

      Matches the specified raw password with the specified encoded representation.

      Specified by:
      matches in interface Password.Encoder<SCryptPassword,SCryptPassword.Encoder>
      Parameters:
      raw - a raw password
      encoded - an encoded password
      Returns:
      true if passwords match, false otherwise
      Throws:
      PasswordException - if there was an error matching passwords
    • hashCode

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

      public boolean equals(Object obj)
      Overrides:
      equals in class Object