VaultKMP

A Kotlin Multiplatform secure encrypted key-value storage library.
Features
- 🔐 Secure - AES-256-GCM encryption with platform-native key storage
- 🌍 Multiplatform - Android, iOS, JVM Desktop, JavaScript, WASM
- 🎯 Type-Safe - Compile-time type checking with dedicated entry classes
- ⚡ Coroutine-based - Modern async API with Kotlin Coroutines
- 📡 Observable - Flow-based observation of value changes
- 🔧 Configurable - Builder pattern for flexible configuration
Platform Implementation
*JS/WASM uses simplified encryption due to Web Crypto API limitations
Installation
Add the dependency to your build.gradle.kts:
kotlin {
sourceSets {
commonMain.dependencies {
implementation("in.sitharaj:vaultkmp:1.0.0")
}
}
}
dependencies {
implementation("in.sitharaj:vaultkmp:1.0.0")
}
Quick Start
Basic Usage
import `in`.sitharaj.vaultkmp.VaultStore
import `in`.sitharaj.vaultkmp.VaultConfig
val vault = VaultStore.create {
name("my_secrets")
encryptionLevel(EncryptionLevel.HIGH)
}
vault.putString(, )
vault.putInt(, )
vault.putBoolean(, )
token = vault.getString()
userId = vault.getInt(, default = )
Type-Safe Entries
val tokenEntry = vault.stringEntry("auth_token")
val userIdEntry = vault.intEntry("user_id", default = 0)
val isPremiumEntry = vault.booleanEntry("is_premium", default = false)
tokenEntry.set("new_token")
val token = tokenEntry.get()
val hasToken = tokenEntry.isSet()
tokenEntry.remove()
Storing Objects
@Serializable
data class UserSettings(
val theme: String,
val notifications: Boolean
)
val settingsEntry = vault.objectEntry(
key = "settings",
serializer = UserSettings.serializer(),
default = UserSettings("light", true)
)
settingsEntry.set(UserSettings("dark", false))
val settings = settingsEntry.getOrDefault()
Observing Changes
vault.observeString("auth_token").collect { token ->
println("Token changed: $token")
}
Platform Setup
Android
Initialize in your Application class:
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
PlatformVault.initialize(this)
}
}
iOS
No special setup required. Uses NSUserDefaults with AES-256-GCM encryption.
Desktop
No special setup required. Files stored in ~/.vaultkmp/.
API Reference
VaultStore
VaultConfig.Builder
License
Copyright 2024 Sitharaj Seenivasan
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance the License.
You may obtain a copy of the License at
http:
Unless applicable law agreed to writing, software
distributed under the License distributed an BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express implied.
See the License the specific language governing permissions
limitations under the License.