Skip to content

Commit bd8a16c

Browse files
authored
Update README.md
1 parent ab1d5a4 commit bd8a16c

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

README.md

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,51 @@ Check out my own video about how easy it is to adapt KSafe into your project and
2323

2424
## What is KSafe
2525

26-
KSafe is the **easiest and most secure** way to persist encrypted data in Kotlin Multiplatform.
26+
#### KSafe is the
27+
1. **easiest to use**
28+
2. **most secure**
29+
3. **fastest**
30+
31+
library to persist encrypted and unencrypted data in Kotlin Multiplatform.
2732

2833
With simple property delegation, encrypted values feel like normal variables — you just read and write them, and KSafe handles encryption, decryption, and persistence transparently across all four platforms: **Android**, **iOS**, **JVM/Desktop**, and **WASM/JS (Browser)**.
2934

35+
Here's what that looks like in a real app — Ktor bearer authentication with **zero encryption boilerplate**:
36+
3037
```kotlin
31-
var token by ksafe("") // encrypted, persisted, works on all 4 platforms
32-
token = "abc123" // that's it
38+
@Serializable
39+
data class AuthTokens(
40+
val accessToken: String = "",
41+
val refreshToken: String = ""
42+
)
43+
44+
// One line to encrypt, persist, and serialize the whole object
45+
var tokens by ksafe(AuthTokens())
46+
47+
install(Auth) {
48+
bearer {
49+
loadTokens {
50+
// Reads atomic object from hot cache (~0.002ms). No disk. No suspend.
51+
BearerTokens(tokens.accessToken, tokens.refreshToken)
52+
}
53+
refreshTokens {
54+
val newInfo = api.refreshAuth(tokens.refreshToken)
55+
56+
// Atomic update: encrypts & persists as JSON in background (~13μs)
57+
tokens = AuthTokens(
58+
accessToken = newInfo.accessToken,
59+
refreshToken = newInfo.refreshToken
60+
)
61+
62+
BearerTokens(tokens.accessToken, tokens.refreshToken)
63+
}
64+
}
65+
}
3366
```
3467

35-
Under the hood, each platform uses its native crypto engine — Android Keystore, iOS Keychain + CryptoKit, JVM's javax.crypto, and browser WebCrypto — unified behind a single API. Values are AES-256-GCM encrypted and persisted to DataStore (or localStorage on WASM). Beyond property delegation, KSafe also offers Compose state integration (`ksafe.mutableStateOf()`), reactive flows (`getFlow()` / `getStateFlow()`), built-in biometric authentication, configurable memory policies, and runtime security detection (root/jailbreak, debugger, emulator) — all out of the box.
68+
No explicit encrypt/decrypt calls. No DataStore boilerplate. No `runBlocking`. Tokens are AES-256-GCM encrypted at rest, served from the hot cache at runtime, and survive process death — all through regular Kotlin property access.
3669

37-
Whether you need to secure OAuth tokens in a banking app or remember the last-visited screen of your game, KSafe stores the data encrypted with platform-specific secure key storage and hands it back to you like a normal variable.
70+
Under the hood, each platform uses its native crypto engine — Android Keystore, iOS Keychain + CryptoKit, JVM's javax.crypto, and browser WebCrypto — unified behind a single API. Values are AES-256-GCM encrypted and persisted to DataStore (or localStorage on WASM). Beyond property delegation, KSafe also offers Compose state integration (`ksafe.mutableStateOf()`), reactive flows (`getFlow()` / `getStateFlow()`), built-in biometric authentication, configurable memory policies, and runtime security detection (root/jailbreak, debugger, emulator) — all out of the box.
3871

3972
***
4073

0 commit comments

Comments
 (0)