# Encrypt on linux, decrypt in IOS application issues

**URL:** <https://discuss.zetetic.net/t/encrypt-on-linux-decrypt-in-ios-application-issues/1585>\
**Category:** SQLCipher\
**Created:** [August 11, 2016, 12:49am UTC](https://discuss.zetetic.net/t/encrypt-on-linux-decrypt-in-ios-application-issues/1585 "2016-08-11T00:49:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alizons\_Nematovs](https://avatars.discourse-cdn.com/v4/letter/a/91b2a8/32.png) [@Alizons\_Nematovs](https://discuss.zetetic.net/u/Alizons_Nematovs)\
**Post date:** [August 11, 2016, 12:49am UTC](https://discuss.zetetic.net/t/encrypt-on-linux-decrypt-in-ios-application-issues/1585/1 "2016-08-11T00:49:03Z")

</div>

Hello

We have an issue SQLCipher and we cannot figure out why it is not working. Basically , our current pipeline is setup in such a way

1. We build SQLITE DB on mac OS
2. We encrypt it with SQLCipher on mac OS
3. we decrypt it in IOS app

Now, what we are trying to change is to move step 1 and 2 to linux machines. I was able to install everything on ubuntu image and tried to encrypt DB(which was created on Mac OS) on ubuntu with using raw queries:

> sqlite\> ATTACH DATABASE ‘encrypted.db’ AS encrypted KEY ‘testkey’;  
> sqlite\> SELECT sqlcipher\_export(‘encrypted’);

> sqlite\> DETACH DATABASE encrypted;  
> sqlite\> .exit

I was able to encrypt it and to decrypt it if I am using raw queries. Everything works fine. But I cannot decrypt  
encrypted database in IOS application. It is just returning error 26 file is encrypted or not a database. I tried to use both sqlite3\_key and “PRAGMA key = ‘xxx’”, but it is still returning the same error…Could it be something related to OS? darwin vs linux? I spent 2 days on that, but I cant find any clue… Any help will be greatly appreciated

UPDATE 1 :  
I noticed that our IOS app is using very old cipher version - 2.0.6, while on Ubuntu I have 3.4.0

---

<div class="post-metadata">

**Author:** ![developernotes](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/developernotes/32/1309_2.png) [@developernotes](https://discuss.zetetic.net/u/developernotes)\
**Post date:** [August 11, 2016, 2:03pm UTC](https://discuss.zetetic.net/t/encrypt-on-linux-decrypt-in-ios-application-issues/1585/2 "2016-08-11T14:03:59Z")

</div>

Hi @Alizons_Nematovs

What versions of SQLCipher are being used on both the Linux and iOS side? You can determine this by executing the following command:

```
PRAGMA cipher_version;

```

Were there any runtime configuration changes made when creating the database (e.g., kdf\_iter, cipher, cipher\_use\_hmac, etc)?

---

<div class="post-metadata">

**Author:** ![Alizons\_Nematovs](https://avatars.discourse-cdn.com/v4/letter/a/91b2a8/32.png) [@Alizons\_Nematovs](https://discuss.zetetic.net/u/Alizons_Nematovs)\
**Post date:** [August 11, 2016, 6:06pm UTC](https://discuss.zetetic.net/t/encrypt-on-linux-decrypt-in-ios-application-issues/1585/3 "2016-08-11T18:06:09Z")

</div>

Hi @developernotes,

Thank you for the prompt response!  
We didnt do any runtime config changes in my knowledge.  
IOS app has cipher version 2.0.6 and yesterday I was able to download and compile the same old version on Linux machine from [Release v2.0.6 · sqlcipher/sqlcipher · GitHub](https://github.com/sqlcipher/sqlcipher/releases/tag/v2.0.6). Both sqlite3 version and SQLCipher  
versions are identical now on IOS and Linux

Please see below code from ios app, perhaps it will help you to understand why it is not working

Open database:

> int err = sqlite3\_open((\_databasePath ? [\_databasePath fileSystemRepresentation] : “:memory:”), &\_db );

Setting pragma key:

> int rc = sqlite3\_key(\_db, [key UTF8String], (int)strlen([key UTF8String]));

Making queries:

> rc = sqlite3\_prepare\_v2(\_db, [sql UTF8String], -1, &pStmt, 0);

First query we are making after DB is opened and key is set is “PRAGMA integrity\_check”.  
Thank you!

---

<div class="post-metadata">

**Author:** ![Alizons\_Nematovs](https://avatars.discourse-cdn.com/v4/letter/a/91b2a8/32.png) [@Alizons\_Nematovs](https://discuss.zetetic.net/u/Alizons_Nematovs)\
**Post date:** [August 11, 2016, 8:47pm UTC](https://discuss.zetetic.net/t/encrypt-on-linux-decrypt-in-ios-application-issues/1585/4 "2016-08-11T20:47:10Z")

</div>

I think we sorted that out. Apparently it was a version mismatch. We had another sqlite version installed on linux machine, so once we got rid of that sqlite cipher and sqlite versions are matching now and it is working fine. Apologies, and thank you for your reponse

P.S. Can be useful for someone - if you are using old version of SQLCipher, like 2.0.6. you will notice that there is no sqlcipher executable after make is done. sqlcipher is bundled inside sqlite3, so use sqlite3 instead.
