CredentialKeychain

Synchronous secure credential storage, backed by the current platform's native secure storage (Android Keystore, Apple Keychain, macOS Keychain, Linux Secret Service, or Windows DPAPI). Call from a worker thread: native stores may block or prompt the user. Implementations never persist plaintext as a fallback — an unavailable or failing backend throws KeychainUnavailableException instead.

Obtain an instance with forCurrentPlatform. On Android, use the Context-taking overload declared in the com.maniramezan.credentialkeychain Android package instead.

val keychain = CredentialKeychain.forCurrentPlatform(serviceName = "my-app", accountName = "user-123")
keychain.write("api-key", "secret-token")
val token: String? = keychain.read("api-key")
keychain.delete("api-key")

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 needing to know the individual keys. Other namespaces are untouched. Clearing an empty namespace succeeds silently as long as the backend itself is available.

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

Deletes the entry stored under key. Deleting a key that has no entry succeeds silently as long as the backend itself is available.

Link copied to clipboard
abstract fun read(key: String): String?

Reads the value stored under key.

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

Stores value under key, replacing any existing entry. Values are stored exactly, including leading/trailing whitespace. To remove an entry, call delete.