ProtectedKeychain

Secret storage whose reads require the user to authenticate with a strong biometric (Class 3 on Android; Face ID or Touch ID on Apple platforms). Writing, deleting, and clearing need no authentication.

Each entry is protected by a key that is invalidated when biometric enrollment changes, so adding a fingerprint or face makes existing entries unreadable: read then throws KeychainUnavailableException with AuthenticationInvalidated, and the caller must delete the entry and write it again after the user signs in another way.

Supported on Android (API 23+), iOS 15+, and macOS 12+ in apps with keychain entitlements. tvOS, watchOS, and desktop JVM stores throw Unsupported from every operation.

Obtain an instance with forCurrentPlatform. On Android, use the overload that takes a Context and an activity provider instead.

Types

Link copied to clipboard
object Companion

Platform-specific factories for creating an application-scoped store.

Functions

Link copied to clipboard
abstract fun clear()

Deletes every entry in this store's service/account namespace without authentication.

Link copied to clipboard
abstract fun delete(key: String)

Deletes the entry stored under key without authentication. Deleting a missing entry succeeds silently.

Link copied to clipboard
abstract suspend fun read(key: String, prompt: AuthenticationPrompt): String?

Shows a biometric prompt and, once the user authenticates, returns the value stored under key. Suspends without blocking the calling thread while the prompt is visible.

Link copied to clipboard
abstract fun write(key: String, value: String)

Stores value under key, replacing any existing entry, without authentication.