SQLCipher, iOS and Swift


#1

Hi,

I have a Swift iOS project that uses SQLite.swift framework and SQLCipher, but is not working as expected.

I setup SQLCipher using Cocoapods. My understandings that installing it via Cocoapods should setup everything correctly.

I am also using an extension to the Connection object to set the key:
import SQLite
import SQLCipher

extension Connection {

public func key(key: String) throws {
    sqlite3_key(handle, key, Int32(key.utf8.count))
    try execute(
        "CREATE TABLE \"__SQLCipher.swift__\" (\"cipher key check\");\n" +
        "DROP TABLE \"__SQLCipher.swift__\";"
    )
}

}

Creating the Database on startup works fine, but the screen goes black with no errors when using the key method above.
Would be grateful for any help

Regards,

Pepe


#2

Hi @pepe

It sounds like you may have several components at play here which could be causing you issues. Are you using this?


#3

Hi,

thank you for getting back to me.

I am using SQLCipher and SQLite.swift via cocoapods. I am currently not using the library you referred to.
I gave that library a go a while back, but ended up with compilation errors. I could give it another try.

Is it needed for this to work?


#4

Hi @pepe

You can not use both SQLite.swift together with SQLCipher. You might consider only using SQLiteCipher.swift which utilizing SQLite.swift packaged with SQLCipher, or SQLCipher via cocoapods directly along with a bridging header that includes the following for Swift integration:

#define SQLITE_HAS_CODEC 1
#include "sqlite3.h"

#6

Hi,

SQLiteCipher doesnt seem to work with Cocoapods: https://github.com/stephencelis/SQLiteCipher.swift/issues/3

Your second alternative to use SQLCipher via Cocoapods and adding the bridging header. That would require us to refactor the existing code, since we use SQLite.swift

Is there any way to make this work with my initial approach (SQLCipher and SQLite.swift installed via Cocoapods) above? Where I add an extension to the Connection object?


#7

Hello @pepe,

If you do not wish to use SQLCipher via cocoapods directly with the bridging header, you might consider taking a look at an existing pull request that resolves the issues around including SQLCipher with SQLiteCipher.swift.


#8

Hi,

thank you for your answer. Yeah, using SQLCipher via cocoapods directly would mean refactor all the code, since it is using SQLite.swift. Looked at the PR you linked to, but didn’t see any solution that could help me. Anyway, thanks for your time.