public class PBKDF2Engine extends java.lang.Object implements PBKDF2
Version 2.0
PBKDF2 (P, S, c, dkLen)
Options:
Input:
Output:
| Modifier and Type | Field and Description |
|---|---|
protected PBKDF2Parameters |
parameters |
protected PRF |
prf |
| Constructor and Description |
|---|
PBKDF2Engine()
Constructor for PBKDF2 implementation object.
|
PBKDF2Engine(PBKDF2Parameters parameters)
Constructor for PBKDF2 implementation object.
|
PBKDF2Engine(PBKDF2Parameters parameters,
PRF prf)
Constructor for PBKDF2 implementation object.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
_F(byte[] dest,
int offset,
PRF prf,
byte[] S,
int c,
int blockIndex)
Function F.
|
protected void |
assertPRF(byte[] P)
Factory method.
|
protected int |
ceil(int a,
int b)
Integer division with ceiling function.
|
byte[] |
deriveKey(java.lang.String inputPassword)
Convert String-based input to internal byte array, then invoke PBKDF2.
|
byte[] |
deriveKey(java.lang.String inputPassword,
int dkLen)
Convert String-based input to internal byte array, then invoke PBKDF2.
|
PBKDF2Parameters |
getParameters()
Allow reading of configured parameters.
|
PRF |
getPseudoRandomFunction()
Get currently set Pseudo Random Function.
|
protected void |
INT(byte[] dest,
int offset,
int i)
Four-octet encoding of the integer i, most significant octet first.
|
static void |
main(java.lang.String[] args)
Convenience client function.
|
protected byte[] |
PBKDF2(PRF prf,
byte[] S,
int c,
int dkLen)
Core Password Based Key Derivation Function 2.
|
void |
setParameters(PBKDF2Parameters parameters)
Allow setting of configured parameters.
|
void |
setPseudoRandomFunction(PRF prf)
Set the Pseudo Random Function to use.
|
boolean |
verifyKey(java.lang.String inputPassword)
Convert String-based input to internal byte arrays, then invoke PBKDF2
and verify result against the reference data that is supplied in the
PBKDF2Parameters.
|
protected void |
xor(byte[] dest,
byte[] src)
Block-Xor.
|
protected PBKDF2Parameters parameters
protected PRF prf
public PBKDF2Engine()
public PBKDF2Engine(PBKDF2Parameters parameters)
parameters - Data holder for iteration count, method to use et cetera.public PBKDF2Engine(PBKDF2Parameters parameters, PRF prf)
parameters - Data holder for iteration count, method to use et cetera.prf - Supply customer Pseudo Random Function.public byte[] deriveKey(java.lang.String inputPassword)
PBKDF2public byte[] deriveKey(java.lang.String inputPassword,
int dkLen)
PBKDF2public boolean verifyKey(java.lang.String inputPassword)
PBKDF2protected void assertPRF(byte[] P)
P - User-supplied candidate password as array of bytes.public PRF getPseudoRandomFunction()
PBKDF2getPseudoRandomFunction in interface PBKDF2protected byte[] PBKDF2(PRF prf, byte[] S, int c, int dkLen)
prf - Pseudo Random Function (i.e. HmacSHA1)S - Salt as array of bytes. null means no salt.c - Iteration count (see RFC 2898 4.2)dkLen - desired length of derived key.protected int ceil(int a,
int b)
a - Numeratorb - Denominatorprotected void _F(byte[] dest,
int offset,
PRF prf,
byte[] S,
int c,
int blockIndex)
dest - Destination byte bufferoffset - Offset into destination byte bufferprf - Pseudo Random FunctionS - Salt as array of bytesc - Iteration countblockIndex - The block index (>= 1).protected void xor(byte[] dest,
byte[] src)
dest - destination byte buffersrc - source bytesprotected void INT(byte[] dest,
int offset,
int i)
dest - destination byte bufferoffset - zero-based offset into desti - the integer to encodepublic PBKDF2Parameters getParameters()
PBKDF2getParameters in interface PBKDF2public void setParameters(PBKDF2Parameters parameters)
PBKDF2setParameters in interface PBKDF2parameters - The parameters object to set.public void setPseudoRandomFunction(PRF prf)
PBKDF2setPseudoRandomFunction in interface PBKDF2prf - Pseudo Random Function to set.public static void main(java.lang.String[] args)
throws java.io.IOException,
java.security.NoSuchAlgorithmException
Example: Password "password" (without the quotes) leads to 48290A0B96C426C3:1000:973899B1D4AFEB3ED371060D0797E0EE0142BD04
The iteration count is configurable. In verification mode, the iteration count supplied in the candidate string must be no less than the
args - Supply the password as argument.java.io.IOException - apparently declared, but never thrownjava.security.NoSuchAlgorithmException - Thrown if underlying crypto library does not support
requested algorithms (SHA1PRNG, HmacSHA1).