KVault is a secure key-value storage for Kotlin Multiplatform projects. It acts as an iOS Keychain wrapper and implements encrypted SharedPreferences for Android.
repositories {
maven { url = uri("https://dl.bintray.com/liftric/maven/") }
}
Then, simply add the dependencies to your sourceSets:
sourceSets {
val commonMain by getting {
dependencies {
implementation("com.liftric:kvault:<version>")
}
}
}
val kVault = KVault(context = Context)
You can create an instance by using the primary or secondary constructor. The primary constructor sets the service name (Used to identify keychain entries) to your main bundle identifier. In case that it can't retrieve the identifier it will be set to com.liftric.KVault
. The access group (Identifier used to share keychains between apps) will be set to null.
val kVault = KVault()
// or
val kVault = KVault(serviceName = "com.company.identifier", accessGroup = null)
Objects can be inserted with the correspondending set method.
val stringStoredSuccessfully: Boolean = set(key = "PASSWORD", value = "546hfbfzzeujfdbfdz")
val intStoredSuccessfully: Boolean = set(key = "SECRET", value = 45678765)
val floatStoredSuccessfully: Boolean = set(key = "HEIGHT", value = 1.79)
- String
- Int
- Long
- Float
- Double
- Bool
Casted values can be retrieved with type methods.
val stringValue: String = string(forKey = "PASSWORD")
val intValue: Int = int(forKey = "SECRET")
It's also possible to check if an object with a given key is in the keychain.
val objectExists = existsObject(forKey = "PASSWORD")
Either a single object or all at once can be deleted.
val removed: Boolean = removeObject(forKey = "PASSWORD")
clear() // Removes all objects that are linked to the service name
KVault is available under the MIT license. See the LICENSE file for more info.