What is KSafe?
mainKSafe is a secure-by-default Kotlin Multiplatform (KMP) key/value persistence library. It allows you to persist ordinary Kotlin variables, Compose MutableState, MutableStateFlow, and @Serializable objects across app restarts on Android, iOS, macOS, JVM/Desktop, WASM, and Kotlin/JS.
Key Features
- Encrypted by default: Uses AES-256-GCM. You can opt-out to plain storage using
mode = KSafeWriteMode.Plain. - Synchronous API: Reads hit a hot in-memory cache, making them non-blocking. Writes are performed in the background.
- Asynchronous API: Provides a
suspendAPI (get/put) if you need to explicitly await a disk flush. - Property Delegate: Use the
ksafe()delegate to treat persisted values like normal variables without boilerplate.
var counter by ksafe(0)
counter++ // auto-encrypted (AES-256-GCM), auto-persisted, survives process death