Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Ctors](https://developer.android.com/reference/java/security/KeyStore.PasswordProtection#pubctors) \| [Methods](https://developer.android.com/reference/java/security/KeyStore.PasswordProtection#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/java/security/KeyStore.PasswordProtection#inhmethods)

# KeyStore.PasswordProtection


`
public
static


class
KeyStore.PasswordProtection
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


implements

https://developer.android.com/reference/javax/security/auth/Destroyable,

https://developer.android.com/reference/java/security/KeyStore.ProtectionParameter


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | java.security.KeyStore.PasswordProtection |

<br />

*** ** * ** ***

A password-based implementation of `ProtectionParameter`.

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/java/security/KeyStore.PasswordProtection#PasswordProtection(char[])(char[] password) ` Creates a password parameter. |
| ` https://developer.android.com/reference/java/security/KeyStore.PasswordProtection#PasswordProtection(char[],%20java.lang.String,%20java.security.spec.AlgorithmParameterSpec)(char[] password, https://developer.android.com/reference/java/lang/String protectionAlgorithm, https://developer.android.com/reference/java/security/spec/AlgorithmParameterSpec protectionParameters) ` Creates a password parameter and specifies the protection algorithm and associated parameters to use when encrypting a keystore entry. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/java/security/KeyStore.PasswordProtection#destroy()() ` Clears the password. |
| ` char[]` | ` https://developer.android.com/reference/java/security/KeyStore.PasswordProtection#getPassword()() ` Gets the password. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/security/KeyStore.PasswordProtection#getProtectionAlgorithm()() ` Gets the name of the protection algorithm. |
| ` https://developer.android.com/reference/java/security/spec/AlgorithmParameterSpec` | ` https://developer.android.com/reference/java/security/KeyStore.PasswordProtection#getProtectionParameters()() ` Gets the parameters supplied for the protection algorithm. |
| ` boolean` | ` https://developer.android.com/reference/java/security/KeyStore.PasswordProtection#isDestroyed()() ` Determines if password has been cleared. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(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` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(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` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||
| From interface ` https://developer.android.com/reference/javax/security/auth/Destroyable ` |---|---| | ` default void` | ` https://developer.android.com/reference/javax/security/auth/Destroyable#destroy()() ` Destroy this `Object`. | | ` default boolean` | ` https://developer.android.com/reference/javax/security/auth/Destroyable#isDestroyed()() ` Determine if this `Object` has been destroyed. | ||

## Public constructors

### PasswordProtection

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public PasswordProtection (char[] password)
```

Creates a password parameter.

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

<br />

| Parameters ||
|---|---|
| `password` | `char`: the password, which may be `null` <br /> |

### PasswordProtection

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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

<br />

| Parameters ||
|---|---|
| `password` | `char`: the password, which may be `null` <br /> |
| `protectionAlgorithm` | `String`: the encryption algorithm name, for example, `PBEWithHmacSHA256AndAES_256`. See the Cipher section in the [Java Security Standard Algorithm Names Specification](https://docs.oracle.com/en/java/javase/17/docs/specs/security/standard-names.html#cipher-algorithm-names) for information about standard encryption algorithm names. <br /> |
| `protectionParameters` | `AlgorithmParameterSpec`: the encryption algorithm parameter specification, which may be `null` <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException` | if `protectionAlgorithm` is `null` |

## Public methods

### destroy

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void destroy ()
```

Clears the password.

<br />

| Throws ||
|---|---|
| `https://developer.android.com/reference/javax/security/auth/DestroyFailedException` | if this method was unable to clear the password |

### getPassword

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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

<br />

| Returns ||
|---|---|
| `char[]` | the password, which may be `null` <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if the password has been cleared (destroyed) |

**See also:**

- `https://developer.android.com/reference/java/security/KeyStore.PasswordProtection#destroy()`

### getProtectionAlgorithm

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | the algorithm name, or `null` if none was set <br /> |

### getProtectionParameters

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public AlgorithmParameterSpec getProtectionParameters ()
```

Gets the parameters supplied for the protection algorithm.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/security/spec/AlgorithmParameterSpec` | the algorithm parameter specification, or `null`, if none was set <br /> |

### isDestroyed

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isDestroyed ()
```

Determines if password has been cleared.

<br />

| Returns ||
|---|---|
| `boolean` | true if the password has been cleared, false otherwise <br /> |