open class PasswordProtection : Destroyable, KeyStore.ProtectionParameter

A password-based implementation of ProtectionParameter.

Summary

Public constructors

Creates a password parameter.

PasswordProtection(password: CharArray!, protectionAlgorithm: String!, protectionParameters: AlgorithmParameterSpec!)

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

Public methods
open Unit

destroy()

Clears the password.

open CharArray!

Gets the password.

open String!

Gets the name of the protection algorithm.

open AlgorithmParameterSpec!

Gets the parameters supplied for the protection algorithm.

open Boolean

Determines if password has been cleared.

Public constructors

PasswordProtection

PasswordProtection(password: CharArray!)

Creates a password parameter.

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

Parameters
password CharArray!: the password, which may be null

PasswordProtection

PasswordProtection(
    password: CharArray!,
    protectionAlgorithm: String!,
    protectionParameters: AlgorithmParameterSpec!)

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 CharArray!: 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
Exceptions
java.lang.NullPointerException if protectionAlgorithm is null

Public methods

destroy

open fun destroy(): Unit

Clears the password.

Exceptions
java.lang.SecurityException if the caller does not have permission to destroy this Object.
javax.security.auth.DestroyFailedException if this method was unable to clear the password

getPassword

open fun getPassword(): CharArray!

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.

Return
CharArray! the password, which may be null
Exceptions
java.lang.IllegalStateException if the password has been cleared (destroyed)

getProtectionAlgorithm

open fun getProtectionAlgorithm(): String!

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.

Return
String! the algorithm name, or null if none was set

getProtectionParameters

open fun getProtectionParameters(): AlgorithmParameterSpec!

Gets the parameters supplied for the protection algorithm.

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

isDestroyed

open fun isDestroyed(): Boolean

Determines if password has been cleared.

Return
Boolean true if the password has been cleared, false otherwise

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2026-02-13 UTC.