Added in API level 1

KeyStore.PasswordProtection

public static class KeyStore.PasswordProtection
extends Object implements Destroyable, KeyStore.ProtectionParameter

java.lang.Object
   ↳ java.security.KeyStore.PasswordProtection


A password-based implementation of ProtectionParameter.

Summary

Public constructors

PasswordProtection(char[] password)

Creates a password parameter.

PasswordProtection(char[] password, String protectionAlgorithm, AlgorithmParameterSpec protectionParameters)

Creates a password parameter and specifies the protection algorithm and associated parameters to use when encrypting a keystore entry.

Public methods

void destroy()

Clears the password.

char[] getPassword()

Gets the password.

String getProtectionAlgorithm()

Gets the name of the protection algorithm.

AlgorithmParameterSpec getProtectionParameters()

Gets the parameters supplied for the protection algorithm.

boolean isDestroyed()

Determines if password has been cleared.

Inherited methods

Object clone()

Creates and returns a copy of this object.

boolean equals(Object obj)

Indicates whether some other object is "equal to" this one.

void finalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

final Class<?> getClass()

Returns the runtime class of this Object.

int hashCode()

Returns a hash code value for the object.

final void notify()

Wakes up a single thread that is waiting on this object's monitor.

final void notifyAll()

Wakes up all threads that are waiting on this object's monitor.

String toString()

Returns a string representation of the object.

final void wait(long timeoutMillis, int nanos)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait(long timeoutMillis)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait()

Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

default void destroy()

Destroy this Object.

default boolean isDestroyed()

Determine if this Object has been destroyed.

Public constructors

PasswordProtection

Added in API level 1
public PasswordProtection (char[] password)

Creates a password parameter.

The specified password is cloned before it is stored in the new PasswordProtection object.

Parameters
password char: the password, which may be null

PasswordProtection

Added in API level 26
public PasswordProtection (char[] password, 
                String protectionAlgorithm, 
                AlgorithmParameterSpec protectionParameters)

Creates a password parameter and specifies the protection algorithm and associated parameters to use when encrypting a keystore entry.

The specified password is cloned before it is stored in the new PasswordProtection object.

Parameters
password char: the password, which may be null

protectionAlgorithm String: the encryption algorithm name, for example, PBEWithHmacSHA256AndAES_256. See the Cipher section in the Java Security Standard Algorithm Names Specification for information about standard encryption algorithm names.

protectionParameters AlgorithmParameterSpec: the encryption algorithm parameter specification, which may be null

Throws
NullPointerException if protectionAlgorithm is null

Public methods

destroy

Added in API level 1
public void destroy ()

Clears the password.

Throws
DestroyFailedException if this method was unable to clear the password

getPassword

Added in API level 1
public char[] getPassword ()

Gets the password.

Note that this method returns a reference to the password. If a clone of the array is created it is the caller's responsibility to zero out the password information after it is no longer needed.

Returns
char[] the password, which may be null

Throws
IllegalStateException if the password has been cleared (destroyed)

See also:

getProtectionAlgorithm

Added in API level 26
public String getProtectionAlgorithm ()

Gets the name of the protection algorithm. If none was set then the keystore provider will use its default protection algorithm. The name of the default protection algorithm for a given keystore type is set using the 'keystore.<type>.keyProtectionAlgorithm' security property. For example, the keystore.PKCS12.keyProtectionAlgorithm property stores the name of the default key protection algorithm used for PKCS12 keystores. If the security property is not set, an implementation-specific algorithm will be used.

Returns
String the algorithm name, or null if none was set

getProtectionParameters

Added in API level 26
public AlgorithmParameterSpec getProtectionParameters ()

Gets the parameters supplied for the protection algorithm.

Returns
AlgorithmParameterSpec the algorithm parameter specification, or null, if none was set

isDestroyed

Added in API level 1
public boolean isDestroyed ()

Determines if password has been cleared.

Returns
boolean true if the password has been cleared, false otherwise