Code Monkey home page Code Monkey logo

Comments (10)

kpgalligan avatar kpgalligan commented on July 29, 2024

What is "abnormal"?

from sqliter.

DongXinyu avatar DongXinyu commented on July 29, 2024

@kpgalligan I'm sorry to have troubled you. What I'm trying to say is not working properly.

from sqliter.

kpgalligan avatar kpgalligan commented on July 29, 2024

In what way? Doesn't compile? It's not encrypting the data?

from sqliter.

DongXinyu avatar DongXinyu commented on July 29, 2024

@kpgalligan
It compiles normally. When running on an iPhone, the data is not encrypted. When running in the emulator, the database cannot be opened using the key in the code. I downloaded the generated database to my computer and then tried to open it with DB Browser for SQLite.

from sqliter.

kpgalligan avatar kpgalligan commented on July 29, 2024

That has nothing to do with sqliter. That's how you're linking to SQLCipher (or whatever you're using).

from sqliter.

DongXinyu avatar DongXinyu commented on July 29, 2024

I installed SQLCipher correctly.

Call DatabaseConfiguration encryption is normal when Kotlin is set to 1.7.10.

// Project/build.gradle.kts
plugins {
    //trick: for the same plugin versions in all sub-modules
    id("com.android.application").version("7.4.1").apply(false)
    id("com.android.library").version("7.4.1").apply(false)
    kotlin("android").version("1.7.10").apply(false)
    kotlin("multiplatform").version("1.7.10").apply(false)
}

DatabaseConfiguration encryption goes wrong when Kotlin is set to 1.8.0.

// Project/build.gradle.kts
plugins {
    //trick: for the same plugin versions in all sub-modules
    id("com.android.application").version("7.4.1").apply(false)
    id("com.android.library").version("7.4.1").apply(false)
    kotlin("android").version("1.8.0").apply(false)
    kotlin("multiplatform").version("1.8.0").apply(false)
}

1

Android Studio prompts DatabaseConfiguration here:

https://github.com/touchlab/SQLiter/blob/main/sqliter-driver/src/nativeCommonMain/kotlin/co/touchlab/sqliter/DatabaseConfiguration.kt

from sqliter.

DongXinyu avatar DongXinyu commented on July 29, 2024

You mean SQLCipher does not support Kotlin 1.8.0, not related to DatabaseConfiguration, am I understanding correctly?

from sqliter.

kpgalligan avatar kpgalligan commented on July 29, 2024

I mean that if you link to sqlite on iOS, you can pass in an encryption key but it won't matter. You need to bundle and link to SQLCipher. It is very hard to figure anything out without seeing your whole config, but basically you need to confirm that you aren't linking to the included sqlite.

How and when do you include SQLCipher on iOS?

from sqliter.

DongXinyu avatar DongXinyu commented on July 29, 2024

My project uses Kotlin Mulitplatform Mobile and SqlDelight. SQLCipher is used to enhance SQLite for encryption.

I think touchlabSQLiter is the equivalent of middleware, am I getting that right?

Kotlin Mulitplatform Mobile
├── androidMain
├── commonMain
└── iosMain
    └── SqlDelight
        └── touchlabSQLiter
            └── SQLCipher
                └── SQLite

Some of my configurations are as follows:

# project/bulid.gradle.kts
plugins {
    id("com.android.application").version("7.4.1").apply(false)
    id("com.android.library").version("7.4.1").apply(false)
    kotlin("android").version("1.7.10").apply(false)
    /* The encryption problem occurred in 1.8.0 */
    kotlin("multiplatform").version("1.7.10").apply(false)
}

buildscript {
    dependencies {
        classpath("com.squareup.sqldelight:gradle-plugin:1.5.5")
    }
}
# shared/build.gradle.kts
plugins {
    kotlin("multiplatform")
    kotlin("native.cocoapods")
    id("com.android.library")
    id("com.squareup.sqldelight")
}

    cocoapods {
        summary = "Some description for the Shared Module"
        homepage = "Link to the Shared Module homepage"
        version = "1.0.1"
        ios.deploymentTarget = "14.1"
        podfile = project.file("../iosApp/Podfile")
        framework {
            baseName = "shared"
        }
        pod("SQLCipher") { /* Call Cocoapods pod install here to install SQLCipher4.5.3 */
            version = "~> 4.5.3"
        }
    }

    sourceSets {
        val iosArm64Main by getting
        val iosX64Main by getting
        val iosSimulatorArm64Main by getting
        val iosMain by creating {
            dependsOn(commonMain)
            iosArm64Main.dependsOn(this)
            iosX64Main.dependsOn(this)
            iosSimulatorArm64Main.dependsOn(this)
            dependencies {
                implementation("com.squareup.sqldelight:native-driver:1.5.5")
                implementation("co.touchlab:sqliter-driver:1.2.1")
            }
        }

Test equipment:

  1. iPhone Emulator (iOS15 iPhone8Plus)
  2. iPhone Real (iOS15.7.2 iPhone7Plus)
  3. iPhone Real (iOS16.3 iPhone14Pro)

from sqliter.

DongXinyu avatar DongXinyu commented on July 29, 2024
# shared/iosMain/Kotlin/actual.kt

package me.dxy.common.repository

import co.touchlab.sqliter.DatabaseConfiguration
import com.squareup.sqldelight.db.SqlDriver
import com.squareup.sqldelight.drivers.native.NativeSqliteDriver
import com.squareup.sqldelight.drivers.native.wrapConnection
import me.dxy.common.di.MyTestDatabaseWrapper
import me.dxy.mytest.shared.db.MyTestDB
import org.koin.dsl.module

actual fun platformModule() = module {
  single {
    val schema = MyTestDB.Schema
    val databaseConfiguration = DatabaseConfiguration(
      name = "testEncrypt.db",
      version = schema.version,
      create = { connection ->
        wrapConnection(connection) { schema.create(it) }
      },
      upgrade = { connection, oldVersion, newVersion ->
        wrapConnection(connection) {
          schema.migrate(it, oldVersion, newVersion)
        }
      },
      encryptionConfig = DatabaseConfiguration.Encryption("123")
    )
    val driver = NativeSqliteDriver(databaseConfiguration)
    MyTestDatabaseWrapper(MyTestDB(driver))
  }
}
# iosApp/iOSApp.swfit

import SwiftUI
import shared
import SQLCipher

@main
struct iOSApp: App {
    init() {
        KoinKt.doInitKoin()
    }
	var body: some Scene {
		WindowGroup {
			ContentView()
		}
	}
}
# iosApp/ContentView.swfit

import SwiftUI
import shared
import SQLCipher

struct ContentView: View {

	var body: some View {
		Text("Oh yeah!")
                Button("Click me") {
                    MyTestRepository().savePeople()
                }
	}
}

struct ContentView_Previews: PreviewProvider {
	static var previews: some View {
		ContentView()
	}
}

from sqliter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.