Class PBEKeySpec

java.lang.Object
javax.crypto.spec.PBEKeySpec
All Implemented Interfaces:
KeySpec

public class PBEKeySpec
extends Object
implements KeySpec
The key specification for a password based encryption key.

Password based encryption is described in PKCS #5.

  • Constructor Summary

    Constructors
    Constructor Description
    PBEKeySpec​(char[] password)
    Creates a new PBEKeySpec with the specified password.
    PBEKeySpec​(char[] password, byte[] salt, int iterationCount)
    Creates a new PBEKeySpec with the specified password, salt and iteration count.
    PBEKeySpec​(char[] password, byte[] salt, int iterationCount, int keyLength)
    Creates a new PBEKeySpec with the specified password, salt, iteration count and the desired length of the derived key.
  • Method Summary

    Modifier and Type Method Description
    void clearPassword()
    Clears the password by overwriting it.
    int getIterationCount()
    Returns the iteration count of this key specification.
    int getKeyLength()
    Returns the desired key length of the derived key.
    char[] getPassword()
    Returns a copy of the password of this key specification.
    byte[] getSalt()
    Returns a copy of the salt of this key specification.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PBEKeySpec

      public PBEKeySpec​(char[] password)
      Creates a new PBEKeySpec with the specified password.
      Parameters:
      password - the password.
    • PBEKeySpec

      public PBEKeySpec​(char[] password, byte[] salt, int iterationCount, int keyLength)
      Creates a new PBEKeySpec with the specified password, salt, iteration count and the desired length of the derived key.
      Parameters:
      password - the password.
      salt - the salt.
      iterationCount - the iteration count.
      keyLength - the desired key length of the derived key,
      Throws:
      NullPointerException - if the salt is null.
      IllegalArgumentException - if the salt is empty, iteration count is zero or negative or the key length is zero or negative.
    • PBEKeySpec

      public PBEKeySpec​(char[] password, byte[] salt, int iterationCount)
      Creates a new PBEKeySpec with the specified password, salt and iteration count.
      Parameters:
      password - the password.
      salt - the salt.
      iterationCount - the iteration count.
      Throws:
      NullPointerException - if salt is null.
      IllegalArgumentException - if the salt is empty or iteration count is zero or negative.
  • Method Details

    • clearPassword

      public final void clearPassword()
      Clears the password by overwriting it.
    • getPassword

      public final char[] getPassword()
      Returns a copy of the password of this key specification.
      Returns:
      a copy of the password of this key specification.
      Throws:
      IllegalStateException - if the password has been cleared before.
    • getSalt

      public final byte[] getSalt()
      Returns a copy of the salt of this key specification.
      Returns:
      a copy of the salt of this key specification or null if none is specified.
    • getIterationCount

      public final int getIterationCount()
      Returns the iteration count of this key specification.
      Returns:
      the iteration count of this key specification.
    • getKeyLength

      public final int getKeyLength()
      Returns the desired key length of the derived key.
      Returns:
      the desired key length of the derived key.