- All Implemented Interfaces:
KeySpec
Note that this class stores passwords as char arrays instead of
String
objects (which would seem more logical), because the
String class is immutable and there is no way to overwrite its
internal value when the password stored in it is no longer needed. Hence,
this class requests the password as a char array, so it can be overwritten
when done.
-
Constructor Summary
ConstructorsConstructorDescriptionPKCS5DerivedKeySpec
(char[] pwd, byte[] salt, int iterations, int keyLength, String function) Constructor that takes a password, salt, interation count, key length and key encryption function. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
cleaner()
Call the class IBMJCECCACleaner to clean up the password characters of this spec.final String
Returns the algorithm that the key will be used in.final String
Returns the encryption function used to encrypt the key.final int
Returns the iteration count.final int
Returns the key length.final char[]
Returns a clone of the password.final byte[]
getSalt()
Returns a clone of the salt.
-
Constructor Details
-
PKCS5DerivedKeySpec
Constructor that takes a password, salt, interation count, key length and key encryption function.Note that the given password is cloned before it is stored in the new
PKCS5DerivedKeySpec
object.- Parameters:
pwd
- the password.salt
- the salt.iterations
- the iteration count.keyLength
- the key length.function
- the encryption function.
-
-
Method Details
-
getPassword
public final char[] getPassword()Returns a clone of the password.Note that this method returns a clone of sensitive information. It is the caller's responsibility to zero out the information after it is no longer needed.
- Returns:
- A clone of the password
-
getSalt
public final byte[] getSalt()Returns a clone of the salt.Note that this method returns a clone of sensitive information. It is the caller's responsibility to zero out the information after it is no longer needed.
- Returns:
- A clone of the salt
-
getIterationCount
public final int getIterationCount()Returns the iteration count.- Returns:
- the iteration count
-
getKeyLength
public final int getKeyLength()Returns the key length.- Returns:
- the key length
-
getAlgorithm
Returns the algorithm that the key will be used in. Since PKCS5 derived keys have no target algorithm, null is returned.- Returns:
- the algorithm (null for PKCS5 derived keys)
-
getEncryptionFunction
Returns the encryption function used to encrypt the key. For PBKDF1 keys, the encryption function is a hash function like MD5, MD2 or SHA-1. For PBKDF2 keys, the encryption function is a pseudorandom function like HMACMD5 or HMACSHA1.- Returns:
- the encryption function used to encrypt the key
-
cleaner
protected void cleaner()Call the class IBMJCECCACleaner to clean up the password characters of this spec.
-