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


open 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


Name Summary
<init> Keystore(label: String, manual: Boolean = false, wrapper: KeyStoreWrapper = KeyStoreWrapper())
Creates a new instance around a key identified by the given label


Name Summary
label val label: String
The label the cryptographic key is identified as


Name Summary
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 open fun createDecryptCipher(iv: ByteArray): Cipher
Create a cipher initialized for decrypting data with the managed key.
createEncryptCipher open fun createEncryptCipher(): Cipher
Create a cipher initialized for encrypting data with the managed key.
decryptBytes open fun decryptBytes(encrypted: ByteArray): ByteArray
Decrypts data using the managed key.
deleteKey fun deleteKey(): Unit
Deletes the managed key.
encryptBytes open 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.

Extension Functions

Name Summary
loadResourceAsString fun Any.loadResourceAsString(path: String): String
Loads a file from the resources folder and returns its content as a string object.