javax.crypto.spec

Class PBEKeySpec

Implemented Interfaces:
KeySpec

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

void
clearPassword()
Clear the password array by filling it with null characters.
int
getIterationCount()
Get the iteration count, or 0 if it has not been specified.
int
getKeyLength()
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.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

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 Details

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 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.

PBEKeySpec.java -- Wrapper for password-based keys. Copyright (C) 2004, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.