# Database file is not encrypting

**URL:** <https://discuss.zetetic.net/t/database-file-is-not-encrypting/2896>\
**Category:** Issues\
**Created:** [June 7, 2018, 1:17pm UTC](https://discuss.zetetic.net/t/database-file-is-not-encrypting/2896 "2018-06-07T13:17:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![laxminarayanmn](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/laxminarayanmn/32/822_2.png) [@laxminarayanmn](https://discuss.zetetic.net/u/laxminarayanmn)\
**Post date:** [June 7, 2018, 1:17pm UTC](https://discuss.zetetic.net/t/database-file-is-not-encrypting/2896/1 "2018-06-07T13:17:22Z")

</div>

```
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](https://us1.discourse-cdn.com/flex016/uploads/zetetic/original/1X/6b2e24e3b3d40cfbb80a1bc454a6c3c985a1cbf1.png)

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?
```

---

<div class="post-metadata">

**Author:** ![mmoore](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/mmoore/32/858_2.png) [@mmoore](https://discuss.zetetic.net/u/mmoore)\
**Post date:** [June 7, 2018, 3:23pm UTC](https://discuss.zetetic.net/t/database-file-is-not-encrypting/2896/2 "2018-06-07T15:23:14Z")

</div>

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/](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](mailto:support@zetetic.net) and we’ll be happy to assist further.

Thanks!

---

<div class="post-metadata">

**Author:** ![laxminarayanmn](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/laxminarayanmn/32/822_2.png) [@laxminarayanmn](https://discuss.zetetic.net/u/laxminarayanmn)\
**Post date:** [June 7, 2018, 4:43pm UTC](https://discuss.zetetic.net/t/database-file-is-not-encrypting/2896/3 "2018-06-07T16:43:34Z")

</div>

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/](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

---

<div class="post-metadata">

**Author:** ![mmoore](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/mmoore/32/858_2.png) [@mmoore](https://discuss.zetetic.net/u/mmoore)\
**Post date:** [June 7, 2018, 8:03pm UTC](https://discuss.zetetic.net/t/database-file-is-not-encrypting/2896/4 "2018-06-07T20:03:27Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![laxminarayanmn](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/laxminarayanmn/32/822_2.png) [@laxminarayanmn](https://discuss.zetetic.net/u/laxminarayanmn)\
**Post date:** [June 8, 2018, 9:14am UTC](https://discuss.zetetic.net/t/database-file-is-not-encrypting/2896/5 "2018-06-08T09:14:58Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![mmoore](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/mmoore/32/858_2.png) [@mmoore](https://discuss.zetetic.net/u/mmoore)\
**Post date:** [June 8, 2018, 2:39pm UTC](https://discuss.zetetic.net/t/database-file-is-not-encrypting/2896/6 "2018-06-08T14:39:46Z")

</div>

@laxminarayanmn

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