Database file is not encrypting

let cpath = path.cString(using:String.Encoding.utf8)
        let error = sqlite3_open(cpath!, &sqlite3dbConn)
        if error != SQLITE_OK {
            // Open failed, close DB and fail
            NELog("DA - failed to open \(DB_FILE)!")
            
            sqlite3_close(sqlite3dbConn)
            return false
        }
        else
        {
            NDBLog("DA : \(DB_FILE) opened")
        }
        let licensePragma = ("PRAGMA cipher_license = \(licence);" as NSString).utf8String
        var rc = sqlite3_exec(sqlite3dbConn, licensePragma, nil, nil, nil)
        if (rc != SQLITE_OK) {
            let errmsg = String(cString: sqlite3_errmsg(sqlite3dbConn))
            print("Error with cipher_license: \(errmsg)")
            return false
        }
         rc = sqlite3_key(sqlite3dbConn, (password as NSString).utf8String, Int32(password.utf8CString.count))
        if (rc != SQLITE_OK) {
            let errmsg = String(cString: sqlite3_errmsg(sqlite3dbConn))
            NSLog("Error setting key: \(errmsg)")
        }
        let cipherLicense = ("PRAGMA cipher_license;" as NSString).utf8String
        rc = sqlite3_prepare(sqlite3dbConn, cipherLicense, -1, &stmt, nil);
        rc = sqlite3_step(stmt);
        if (rc == SQLITE_ROW){
            rc = sqlite3_column_int(stmt, 0);
            sqlite3_finalize(stmt);
            print("PRAGMA cipher_license; returned \(rc)");
            if(rc == SQLITE_AUTH){
                let errmsg = String(cString: sqlite3_errmsg(sqlite3dbConn))
                print("Failed to apply license key: \(errmsg)")
                sqlite3_close(sqlite3dbConn);
                sqlite3dbConn = nil;
                return false;
            }
        }
        else {
            let errmsg = String(cString: sqlite3_errmsg(self.sqlite3dbConn))
            print("cipher_license: \(errmsg)")
        }
        let createTableQuery = ("CREATE TABLE IF NOT EXISTS t1(a,b);" as NSString).utf8String
        rc = sqlite3_exec(self.sqlite3dbConn, createTableQuery, nil, nil, nil)
        if (rc != SQLITE_OK){
            let errmsg = String(cString: sqlite3_errmsg(self.sqlite3dbConn))
            print("Failed to create table: \(errmsg)")
            return false
        }else {
            let errmsg = String(cString: sqlite3_errmsg(self.sqlite3dbConn))
            print("successfully created table: \(errmsg)")
        }

this is hexdump result
00%20PM

I’m getting result 21 in sqlite3_key(sqlite3dbConn, (password as NSString).utf8String, Int32(password.utf8CString.count))

and result 101 in     sqlite3_prepare(sqlite3dbConn, cipherLicense, -1, &stmt, nil);

what is the problem in this code?

Hi @laxminarayanmn

Thank you for your support of SQLCipher and for posting on the discussion forum, although I’m sorry to hear about the troubles integrating SQLCipher.

A couple of questions:

  1. Did you follow these steps when integrating SQLCipher: https://www.zetetic.net/sqlcipher/sqlcipher-binaries-ios-and-osx/ ?
  2. Can you successfully run the demo application included?

I took a quick look at the code you posted and don’t see anything that stands out as being incorrect (and running it successfully encrypted a database locally for me).

Because of this, I believe the issue may be related to an integration/project configuration problem.

If you’d prefer, because you’re a commercial license holder, we’d be happy to provide you with private support. Please write us at support@zetetic.net and we’ll be happy to assist further.

Thanks!

Hi @mmoore

I’m able run the demo application using my licence key.
also followed integration steps as suggested in https://www.zetetic.net/sqlcipher/sqlcipher-binaries-ios-and-osx/

and i’ll once again redo this process , if problem still exists i’ll contact private support.

Thanks for your help

regards
Lucky

@laxminarayanmn

You can test that SQLCipher is being correct integrated by executing PRAGMA cipher_version; and checking the column text for the version similar to the examples in the code within the integration steps page.

Cheers,
Micah

@mmoore

logDetails

PRAGMA cipher_license; returned 0
cipher_version: 3.4.2
Failed to create table: file is not a database

now i’m getting new error as file is not a database while creating the Table

regards
Lucky

@laxminarayanmn

Thanks for checking this. We received your private support email, and will follow up with you there.
Cheers,
Micah