javax.crypto.spec

Class PBEKeySpec

public class PBEKeySpec extends Object implements KeySpec

A wrapper for a password-based key, used for password-based encryption (PBE).

Examples of password-based encryption algorithms include:

Since: 1.4

See Also: SecretKeyFactory PBEParameterSpec

Constructor Summary
PBEKeySpec(char[] password)
Create a new PBE key spec with just a password.
PBEKeySpec(char[] password, byte[] salt, int iterationCount)
Create a PBE key spec with a password, salt, and iteration count.
PBEKeySpec(char[] password, byte[] salt, int iterationCount, int keyLength)
Create a PBE key spec with a password, salt, iteration count, and key length.
Method Summary
voidclearPassword()
Clear the password array by filling it with null characters.
intgetIterationCount()
Get the iteration count, or 0 if it has not been specified.
intgetKeyLength()
Get the generated key length, or 0 if it has not been specified.
char[]getPassword()
Get the password character array copy.
byte[]getSalt()
Get the salt bytes array copy.

Constructor Detail

PBEKeySpec

public PBEKeySpec(char[] password)
Create a new PBE key spec with just a password.

A copy of the password argument is stored instead of the argument itself.

Parameters: password The password char array.

PBEKeySpec

public PBEKeySpec(char[] password, byte[] salt, int iterationCount)
Create a PBE key spec with a password, salt, and iteration count.

A copy of the password and salt arguments are stored instead of the arguments themselves.

Parameters: password The password char array. salt The salt bytes. iterationCount The iteration count.

Throws: NullPointerException If salt is null IllegalArgumentException If salt is an empty array, or iterationCount is negative

PBEKeySpec

public PBEKeySpec(char[] password, byte[] salt, int iterationCount, int keyLength)
Create a PBE key spec with a password, salt, iteration count, and key length.

A copy of the password and salt arguments are stored instead of the arguments themselves.

Parameters: password The password char array. salt The salt bytes. iterationCount The iteration count. keyLength The generated key length.

Throws: NullPointerException If salt is null IllegalArgumentException If salt is an empty array, if iterationCount or keyLength is negative

Method Detail

clearPassword

public final void clearPassword()
Clear the password array by filling it with null characters.

This clears the stored copy of the password, not the original char array used to create the password.

getIterationCount

public final int getIterationCount()
Get the iteration count, or 0 if it has not been specified.

Returns: The iteration count, or 0 if it has not been specified.

getKeyLength

public final int getKeyLength()
Get the generated key length, or 0 if it has not been specified.

Returns: The key length, or 0 if it has not been specified.

getPassword

public final char[] getPassword()
Get the password character array copy.

This returns a copy of the password, not the password itself.

Returns: a clone of the password.

Throws: IllegalStateException If {@link #clearPassword()} has already been called.

getSalt

public final byte[] getSalt()
Get the salt bytes array copy.

This returns a copy of the salt, not the salt itself.

Returns: The salt.