# MasterKeys

Artifact: [androidx.security:security-crypto](https://developer.android.com/jetpack/androidx/releases/security) [View Source](https://cs.android.com/search?q=file:androidx/security/crypto/MasterKeys.java+class:androidx.security.crypto.MasterKeys) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/security#1.0.0) Deprecated in [1.1.0](https://developer.android.com/jetpack/androidx/releases/security#1.1.0)

*** ** * ** ***


```
@RequiresApi(value = Build.VERSION_CODES.M)
public final class MasterKeys
```

<br />

*** ** * ** ***

> [!CAUTION]
> **This class is deprecated.**   
>
> Use `https://docs.oracle.com/javase/8/docs/api/javax/crypto/KeyGenerator.html` with AndroidKeyStore instance instead.

Convenient methods to create and obtain master keys in Android Keystore.

The master keys are used to encrypt data encryption keys for encrypting files and preferences.

## Summary

| ### Constants |
|---|---|
| `static final @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/security/keystore/KeyGenParameterSpec.html` | `https://developer.android.com/reference/androidx/security/crypto/MasterKeys#AES256_GCM_SPEC()` **This field is deprecated.** Use `https://developer.android.com/reference/android/security/keystore/KeyGenParameterSpec.Builder.html` instead. <br /> |

| ### Public methods |
|---|---|
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `[getOrCreate](https://developer.android.com/reference/androidx/security/crypto/MasterKeys#getOrCreate(android.security.keystore.KeyGenParameterSpec))(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/security/keystore/KeyGenParameterSpec.html keyGenParameterSpec)` **This method is deprecated.** Deprecated in Java |

## Constants

### AES256_GCM_SPEC

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/security#1.0.0) Deprecated in [1.1.0](https://developer.android.com/jetpack/androidx/releases/security#1.1.0)

```
public static final @NonNull KeyGenParameterSpec AES256_GCM_SPEC
```

> [!CAUTION]
> **This field is deprecated.**   
>
> Use `https://developer.android.com/reference/android/security/keystore/KeyGenParameterSpec.Builder.html` instead.

## Public methods

### getOrCreate

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/security#1.0.0) Deprecated in [1.1.0](https://developer.android.com/jetpack/androidx/releases/security#1.1.0)

```
public static @NonNull String [getOrCreate](https://developer.android.com/reference/androidx/security/crypto/MasterKeys#getOrCreate(android.security.keystore.KeyGenParameterSpec))(@NonNull KeyGenParameterSpec keyGenParameterSpec)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Creates or gets the master key provided

The encryption scheme is required fields to ensure that the type of encryption used is clear to developers.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/security/keystore/KeyGenParameterSpec.html keyGenParameterSpec` | The key encryption scheme |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | The key alias for the master key |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/security/GeneralSecurityException.html` |   |
| `https://developer.android.com/reference/java/io/IOException.html` |   |