# Class Secrets

java.lang.Object
com.codename1.secrets.Secrets

public final class Secrets extends Object

A simple, secure-by-default key/value store for app secrets (auth tokens, API keys, refresh tokens, anything you must not keep in `Preferences` or `Storage` as plaintext).

On a device with a platform keychain wired in (iOS Keychain Services, Android Keystore) the values are protected by the OS secure enclave; if no hardware store is registered, `Secrets` falls back to AES-encrypted storage so a value is never written in the clear. Either way the developer uses the same four calls:

    Secrets.set("auth.token", token);
    String token = Secrets.get("auth.token");
    if (Secrets.contains("auth.token")) { ... }
    Secrets.delete("auth.token");

`isHardwareBacked()` reports whether the active store is the OS keychain (vs the software fallback). A platform port or cn1lib installs a hardware store with `setStore(SecretsStore)` during initialisation; see `SecretsStore`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static boolean`
  `contains(String key)`
  Whether a secret is stored under `key`.
  `static void`
  `delete(String key)`
  Remove the secret stored under `key` (no-op if absent).
  `static String`
  `get(String key)`
  The secret under `key`, or `null` if absent.
  `static String`
  `get(String key, String defaultValue)`
  The secret under `key`, or `defaultValue` if absent.
  `static boolean`
  `isHardwareBacked()`
  Whether the active store is the OS keychain (vs the AES software fallback).
  `static List<String>`
  `keys()`
  Keys of all stored secrets (never the values).
  `static void`
  `set(String key, String value)`
  Store (or replace) `value` under `key`.
  `static void`
  `setStore(SecretsStore s)`
  Install the backing store (called by a platform port / keychain cn1lib at init).

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### setStore

    public static void setStore(SecretsStore s)
    Install the backing store (called by a platform port / keychain cn1lib at init).

  - ### set

    public static void set(String key, String value)
    Store (or replace) `value` under `key`.

  - ### get

    public static String get(String key)
    The secret under `key`, or `null` if absent.

  - ### get

    public static String get(String key, String defaultValue)
    The secret under `key`, or `defaultValue` if absent.

  - ### contains

    public static boolean contains(String key)
    Whether a secret is stored under `key`.

  - ### delete

    public static void delete(String key)
    Remove the secret stored under `key` (no-op if absent).

  - ### keys

    public static List<String> keys()
    Keys of all stored secrets (never the values).

  - ### isHardwareBacked

    public static boolean isHardwareBacked()
    Whether the active store is the OS keychain (vs the AES software fallback).