android-components / mozilla.components.lib.dataprotect / Keystore

# Keystore

`class Keystore` (source)

Manages data protection using a system-isolated cryptographic key.

This class provides for both:

- management for a specific crypto graphic key (identified by a string label)
- protection (encryption/decryption) of data using the managed key

The specific cryptographic properties are pre-chosen to be the following:

- Algorithm is "AES/GCM/NoPadding"
- Key size is 256 bits
- Tag size is 128 bits

### Constructors

<init> | `Keystore(label: String)` Creates a new instance around a key identified by the given label

### Properties

label | `val label: String` The label the cryptographic key is identified as

### Functions

available | `fun available(): Boolean` Determines if the managed key is available for use. Consumers can use this to determine if the key was somehow lost and should treat any previously-protected data as invalid.
createDecryptCipher | `fun createDecryptCipher(iv: ByteArray): Cipher` Create a cipher initialized for decrypting data with the managed key.
createEncryptCipher | `fun createEncryptCipher(): Cipher` Create a cipher initialized for encrypting data with the managed key.
decryptBytes | `fun decryptBytes(encrypted: ByteArray): ByteArray` Decrypts data using the managed key.
deleteKey | `fun deleteKey(): Unit` Deletes the managed key.
encryptBytes | `fun encryptBytes(plain: ByteArray): ByteArray` Encrypts data using the managed key.
generateKey | `fun generateKey(): Boolean` Generates the managed key if it does not already exist.