| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
This project explores encryption techniques for securing local data in Kotlin Multiplatform (KMP) projects, focusing on cross-platform strategies. It demonstrates how to handle sensitive information on both Android and iOS by leveraging platform-specific encryption libraries like CoreCrypto for iOS and Cipher & Keystore for Android. The goal is to achieve seamless data security without sacrificing cross-platform flexibility.
composeApp/src/commonMain/kotlin/com/kmp/encryption/utils/EncryptionManager.kt
This is an interface that defines the encryption and decryption methods.
interface EncryptionManager {
suspend fun encrypt(plainText: String) : ByteArray
suspend fun decrypt(cipherText: ByteArray): String
}
Their implementation is done in the native Android & iOS modules
composeApp/src/commonMain/kotlin/com/kmp/encryption/utils/DataStoreManager.kt
This is a class that uses dataStore to store/retrieve data locally. DataStore is instantiated in the native Android and iOS modules through Koin.
single<DataStore<Preferences>> {
val context = get<Context>()
PreferenceDataStoreFactory.createWithPath(produceFile = {
context.filesDir.resolve(DATASTORE_PREF_FILENAME).absolutePath.toPath()
})
}
single<DataStore<Preferences>> {
PreferenceDataStoreFactory.createWithPath(
produceFile = {
val directory = NSFileManager.defaultManager.URLForDirectory(
directory = NSDocumentDirectory,
inDomain = NSUserDomainMask,
appropriateForURL = null,
create = false,
error = null
)
val filePath = requireNotNull(directory).path()+"/$DATASTORE_PREF_FILENAME"
filePath.toPath()
}
)
}
Presentation slides for this project are available here
| Back | FazBrowse Home | New Git URL |