de.rtner.security.auth.spi
Class SimplePBKDF2

java.lang.Object
  extended by de.rtner.security.auth.spi.PBKDF2Engine
      extended by de.rtner.security.auth.spi.SimplePBKDF2
All Implemented Interfaces:
PBKDF2

public class SimplePBKDF2
extends PBKDF2Engine

PBKDF2 convenience object that comes pre-configured.

Note: this class is not thread-safe. Create a new instance for each thread.

See Also:
RFC 2898

Field Summary
protected  PBKDF2Formatter formatter
           
protected  int saltSize
           
protected  java.security.SecureRandom sr
           
 
Fields inherited from class de.rtner.security.auth.spi.PBKDF2Engine
parameters, prf
 
Constructor Summary
  SimplePBKDF2()
          Constructor for PBKDF2 implementation object that uses defaults.
  SimplePBKDF2(int saltSize, int iterationCount)
          Constructor for PBKDF2 implementation object.
protected SimplePBKDF2(int saltSize, PBKDF2Parameters parameters)
          Extension point.
 
Method Summary
 java.lang.String deriveKeyFormatted(java.lang.String inputPassword)
          Derive key from password, then format.
protected  byte[] generateSalt()
          Generate Salt.
 PBKDF2Formatter getFormatter()
           
 int getSaltSize()
           
 void setFormatter(PBKDF2Formatter formatter)
           
 void setSaltSize(int saltSize)
          Set the desired salt size.
 boolean verifyKeyFormatted(java.lang.String formatted, java.lang.String candidatePassword)
          Verification function.
 
Methods inherited from class de.rtner.security.auth.spi.PBKDF2Engine
_F, assertPRF, ceil, deriveKey, deriveKey, getParameters, getPseudoRandomFunction, INT, main, PBKDF2, setParameters, setPseudoRandomFunction, verifyKey, xor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

saltSize

protected int saltSize

sr

protected java.security.SecureRandom sr

formatter

protected PBKDF2Formatter formatter
Constructor Detail

SimplePBKDF2

public SimplePBKDF2()
Constructor for PBKDF2 implementation object that uses defaults.


SimplePBKDF2

protected SimplePBKDF2(int saltSize,
                       PBKDF2Parameters parameters)
Extension point. Derived classes can call this, then initialize the other members as desired.

Parameters:
saltSize - Salt size.
parameters - Parameters object.

SimplePBKDF2

public SimplePBKDF2(int saltSize,
                    int iterationCount)
Constructor for PBKDF2 implementation object.

Parameters:
saltSize - Salt size.
iterationCount - Iteration count.
Method Detail

getFormatter

public PBKDF2Formatter getFormatter()

setFormatter

public void setFormatter(PBKDF2Formatter formatter)

getSaltSize

public int getSaltSize()

setSaltSize

public void setSaltSize(int saltSize)
Set the desired salt size.

Parameters:
saltSize - Must be positive. Zero or less are rejected.

deriveKeyFormatted

public java.lang.String deriveKeyFormatted(java.lang.String inputPassword)
Derive key from password, then format.

Parameters:
inputPassword - The password to derive key from.
Returns:
"salt:iteration-count:derived-key" (depends on effective formatter)

generateSalt

protected byte[] generateSalt()
Generate Salt. Default is 8 Bytes obtained from SecureRandom.

Returns:
Random Bytes

verifyKeyFormatted

public boolean verifyKeyFormatted(java.lang.String formatted,
                                  java.lang.String candidatePassword)
Verification function.

Parameters:
formatted - "salt:iteration-count:derived-key" (depends on effective formatter). This value should come from server-side storage.
candidatePassword - The password that is checked against the formatted reference data. This value will usually be supplied by the "user" or "client".
Returns:
true verification OK. false verification failed or formatter unable to decode input value as PBKDF2 parameters.