ioannisa
04/14/2026, 12:28 AMgetDirect / putDirect) when you don't want coroutines, plus suspend get / put when you do.
AES-256-GCM with hardware-backed keys by default (Keystore / Keychain / StrongBox / Secure Enclave), or opt out with a single parameter and use KSafe as a fast general-purpose persistence library for plain data.
var token by ksafe("") // plain delegate
var counter by ksafe.mutableStateOf(0) // Compose state
val user: StateFlowUser by ksafe.asStateFlow(User(), scope) // read-only flow
val state: MutableStateFlowUiState by ksafe.asMutableStateFlow(UiState(), scope) // read/write flow
What's new in 1.8.0:
• asMutableStateFlow — drop-in for the classic _state / state pattern, persisted + encrypted transparently:
private val _state by ksafe.asMutableStateFlow(UiState(), viewModelScope)
val state = _state.asStateFlow()
.update { }, .value = …, compareAndSet all behave exactly as you'd expect — persistence is invisible, and it survives process death.
• getOrCreateSecret("main.db") — one line to get a 256-bit passphrase for Room / SQLCipher / SQLDelight (or an API signing key). Generated once, stored hardware-isolated (StrongBox on Android, Secure Enclave on iOS). No more "check if exists, else create and save" boilerplate.
• secureRandomBytes(16) — cryptographically secure random bytes with one API across every target.
• Cross-screen Compose sync via ksafe.mutableStateOf(scope = viewModelScope) — a write in one ViewModel auto-reflects in another.
GitHub: https://github.com/ioannisa/KSafe
Changelog: https://github.com/ioannisa/KSafe/blob/main/CHANGELOG.md