# KeyStoreParameter.Builder

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

# Builder

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/security/KeyStoreParameter.Builder "View this page in Java")  

```
class Builder
```

|---|------------------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                                           ||
| ↳ | [android.security.KeyStoreParameter.Builder](https://developer.android.com/reference/kotlin/android/security/KeyStoreParameter.Builder#) |

*** ** * ** ***

| **This class was deprecated in API level 23.**
|
| Use[KeyProtection.Builder](https://developer.android.com/reference/kotlin/android/security/keystore/KeyProtection.Builder)instead.

Builder class for[KeyStoreParameter](https://developer.android.com/reference/kotlin/android/security/KeyStoreParameter)objects.

This will build protection parameters for use with the[Android KeyStore facility](https://developer.android.com/training/articles/keystore.html).

This can be used to require that KeyStore entries be stored encrypted.

Example:  

```kotlin
KeyStoreParameter params = new KeyStoreParameter.Builder(mContext)
          .setEncryptionRequired()
          .build();
  
```

## Summary

|                                                                                                                                               Public constructors                                                                                                                                               ||
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [Builder](https://developer.android.com/reference/kotlin/android/security/KeyStoreParameter.Builder#Builder(android.content.Context))`(`context:` `[Context](https://developer.android.com/reference/kotlin/android/content/Context.html#)`)` Creates a new instance of the`Builder`with the given`context`. |

|                                                                                                                                                                                                                                                                Public methods                                                                                                                                                                                                                                                                ||
|-------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [KeyStoreParameter](https://developer.android.com/reference/kotlin/android/security/KeyStoreParameter)                  | [build](https://developer.android.com/reference/kotlin/android/security/KeyStoreParameter.Builder#build())`()` Builds the instance of the`KeyStoreParameter`.                                                                                                                                                                                                                                                       |
| [KeyStoreParameter.Builder](https://developer.android.com/reference/kotlin/android/security/KeyStoreParameter.Builder#) | [setEncryptionRequired](https://developer.android.com/reference/kotlin/android/security/KeyStoreParameter.Builder#setEncryptionRequired(kotlin.Boolean))`(`required:` `[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`)` Sets whether this[java.security.KeyStore](https://developer.android.com/reference/kotlin/java/security/KeyStore.html#)entry must be encrypted at rest. |

## Public constructors

### Builder

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

```
Builder(context: Context)
```

Creates a new instance of the`Builder`with the given`context`. The`context`passed in may be used to pop up some UI to ask the user to unlock or initialize the Android KeyStore facility.

|                                                           Parameters                                                           ||
|-----------|---------------------------------------------------------------------------------------------------------------------|
| `context` | [Context](https://developer.android.com/reference/kotlin/android/content/Context.html#):This value cannot be`null`. |

## Public methods

### build

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

```
fun build(): KeyStoreParameter
```

**Deprecated:** *Deprecated in Java.*

Builds the instance of the`KeyStoreParameter`.

|                                                                                 Return                                                                                  ||
|--------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------|
| [KeyStoreParameter](https://developer.android.com/reference/kotlin/android/security/KeyStoreParameter) | built instance of`KeyStoreParameter`This value cannot be`null`. |

|                              Exceptions                              ||
|--------------------------------------|--------------------------------|
| `java.lang.IllegalArgumentException` | if a required field is missing |

### setEncryptionRequired

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

```
fun setEncryptionRequired(required: Boolean): KeyStoreParameter.Builder
```

**Deprecated:** *Data at rest encryption is enabled by default. If extra binding to the lockscreen credential is desired, use[.Builder#setUserAuthenticationRequired(boolean)](https://developer.android.com/reference/kotlin/android/security/keystore/KeyGenParameterSpec). This flag will be ignored from Android S.*

Sets whether this[java.security.KeyStore](https://developer.android.com/reference/kotlin/java/security/KeyStore.html#)entry must be encrypted at rest. Encryption at rest will protect the entry with the secure lock screen credential (e.g., password, PIN, or pattern).

Note that enabling this feature requires that the secure lock screen (e.g., password, PIN, pattern) is set up, otherwise setting the`KeyStore`entry will fail. Moreover, this entry will be deleted when the secure lock screen is disabled or reset (e.g., by the user or a Device Administrator). Finally, this entry cannot be used until the user unlocks the secure lock screen after boot.

|                                                                        Return                                                                        ||
|-------------------------------------------------------------------------------------------------------------------------|-----------------------------|
| [KeyStoreParameter.Builder](https://developer.android.com/reference/kotlin/android/security/KeyStoreParameter.Builder#) | This value cannot be`null`. |

**See Also**

- [android.app.KeyguardManager#isDeviceSecure()](https://developer.android.com/reference/kotlin/android/app/KeyguardManager.html#isDeviceSecure())