# SQLCipher and KMM

DevFeed: [SQLCipher and KMM](<https://devfeed.tech/articles/sqlcipher-and-kmm-25953.md>)

Original publisher: [Read original article](<https://medium.com/@kpgalligan/sqlcipher-and-kmm-58d96ea8095d?source=rss-c2f810aa7890------2>)

Author: Kevin Galligan

Published: 2020-09-23T15:17:52Z

Content type: tutorial

Language: en

Sources: [Stories by Kevin Galligan on Medium](<https://devfeed.tech/sources/stories-by-kevin-galligan-on-medium.md>)

Topics: [Encryption](<https://devfeed.tech/topics/encryption.md>), [multiplatform](<https://devfeed.tech/topics/multiplatform.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [iOS](<https://devfeed.tech/topics/ios.md>), [SQLite](<https://devfeed.tech/topics/sqlite.md>), [cocoapods](<https://devfeed.tech/topics/cocoapods.md>)

Tags: [cocoapods](<https://devfeed.tech/tags/cocoapods.md>), [configuration](<https://devfeed.tech/tags/configuration.md>), [encryption](<https://devfeed.tech/tags/encryption.md>), [ios](<https://devfeed.tech/tags/ios.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-multiplatform](<https://devfeed.tech/tags/kotlin-multiplatform.md>), [kotlin-native](<https://devfeed.tech/tags/kotlin-native.md>), [multiplatform](<https://devfeed.tech/tags/multiplatform.md>), [sqlite](<https://devfeed.tech/tags/sqlite.md>), [upgrade](<https://devfeed.tech/tags/upgrade.md>)

## AI overview

A follow-up tutorial explains how to configure SQLDelight with SQLCipher for Kotlin Multiplatform, focusing on the iOS implementation. It covers forcing a fixed SQLiter version, configuring the native driver, disabling SQLite linking, and adding the SQLCipher dependency through CocoaPods.

## Source excerpt

Here's a quick little followup to Sam's post: Multiplatform Encryption with SQLDelight and SQLCipher. Recently for a client we needed to implement this with Kotlin 1.4.0, and ran into a couple issues. I'm only going to describe how to get the iOS side working as Android is pretty straightforward (although Android is in the sample and video). Here's KaMPKit updated to use SQLCipher touchlab-lab/KaMPKitSQLCipher The cipher key is hardcoded in code. Do *not* do that in your app. You need to get your key from a more secure source. Here's a video showing edits on KaMP Kit: https://medium.com/media/e66f6e9738b614e0f6e2040ef887c0c1/href SQLiter ran into an issue setting the key for SQLCipher. That apparently used to work, but stopped at some point. There was a PR to fix that, but that was not merged in before 0.7.0 was released. 0.7.0 is used in the current version of SQLDelight, so you'll need to force this fixed version. sourceSets["iosMain"].dependencies { implementation("co.touchlab:sqliter:0.7.1") { version { strictly("0.7.1") } } //etc... } We also had an issue with our custom cocoapods fork, so if by chance you're using that, you'll need to use the latest, which is version 0.12. To configure your SQLDelight driver for native, you need to supply a custom DatabaseConfiguration for SQLiter. val schema = YourDb.Schema //SQLDelight Schema val configuration = DatabaseConfiguration( name = "YourDbName", version = schema.version, create = { connection -> wrapConnection(connection) { schema.create(it) } }, upgrade = { connection, oldVersion, newVersion -> wrapConnection(connection) { schema.migrate(it, oldVersion, newVersion ) } } ,key = yourCipherKey ) val driver = NativeSqliteDriver(configuration) To get this all to work in iOS, as discussed in Sam's post, disable sqlite linking: sqldelight { database("YourDb") { packageName = "co.touchlab.yourapp.db" linkSqlite = false } } Then add the SQLCipher dependency (if using cocoapods) cocoapods[ext] { summary = "Shared code for Y