Android APIs
public class

PBEKeySpec

extends Object
implements KeySpec
java.lang.Object
   ↳ javax.crypto.spec.PBEKeySpec

Class Overview

The key specification for a password based encryption key.

Password based encryption is described in PKCS #5.

Summary

Public Constructors
PBEKeySpec(char[] password)
Creates a new PBEKeySpec with the specified password.
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.
PBEKeySpec(char[] password, byte[] salt, int iterationCount)
Creates a new PBEKeySpec with the specified password, salt and iteration count.
Public Methods
final void clearPassword()
Clears the password by overwriting it.
final int getIterationCount()
Returns the iteration count of this key specification.
final int getKeyLength()
Returns the desired key length of the derived key.
final char[] getPassword()
Returns a copy of the password of this key specification.
final byte[] getSalt()
Returns a copy of the salt of this key specification.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public PBEKeySpec (char[] password)

Added in API level 1

Creates a new PBEKeySpec with the specified password.

Parameters
password the password.

public PBEKeySpec (char[] password, byte[] salt, int iterationCount, int keyLength)

Added in API level 1

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.

public PBEKeySpec (char[] password, byte[] salt, int iterationCount)

Added in API level 1

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.

Public Methods

public final void clearPassword ()

Added in API level 1

Clears the password by overwriting it.

public final int getIterationCount ()

Added in API level 1

Returns the iteration count of this key specification.

Returns
  • the iteration count of this key specification.

public final int getKeyLength ()

Added in API level 1

Returns the desired key length of the derived key.

Returns
  • the desired key length of the derived key.

public final char[] getPassword ()

Added in API level 1

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.

public final byte[] getSalt ()

Added in API level 1

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.