Skip to content
/ KVault Public
forked from Liftric/KVault

Secure key-value storage for Kotlin Multiplatform projects.

License

Notifications You must be signed in to change notification settings

rehos/KVault

 
 

Repository files navigation

CI maven-central

KVault

KVault is a secure key-value storage for Kotlin Multiplatform projects. It acts as an iOS Keychain wrapper and implements encrypted SharedPreferences for Android.

Import

Simply add the dependencies to your sourceSets:

sourceSets {
    val commonMain by getting {
        dependencies {
            implementation("com.liftric:kvault:<version>")
        }
    }
}

How-to

Instantiating

Android

  val kVault = KVault(context = Context)

iOS

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)

Setting

Objects can be inserted with the corresponding 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)

Supported Types

  • String
  • Int
  • Long
  • Float
  • Double
  • Bool

Getting

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")

Deleting

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

License

KVault is available under the MIT license. See the LICENSE file for more info.

About

Secure key-value storage for Kotlin Multiplatform projects.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Kotlin 73.3%
  • Swift 26.7%