Do I need to configure before following steps mentioned in SQLCipher iOS tutorial?


Hi All

I have followed the steps mentioned in
but I am not able to encrypt the db. I am using open source (community edition) of SQLCipher. Do I need to configure as mentioned in before following the steps for iOS?

And does sqlcipher_export function requires paid version only? As I want to implement SQLCipher encryption and decryption on existing db.

I have a existing Xcode project with existing db in which I want to use SQLCipher for security purpose. In order to do this I’m facing above problems.

Thank you


Hi @guptag, the basic features of SQLCipher are available in the community edition, sqlcipher_export included, are you getting an error when you try to use it? The various commercial editions provide developer support, like pre-built binaries, solutions for Visual Studio, etc.

I am not able to encrypt the db

Can you tell us what happened? Also, can you share with us the code you are using to encrypt the db and check that you succeeded?

Do I need to configure as mentioned in before following the steps for iOS?

You shouldn’t have to do that, no. The instructions at /introduction are for a generic build on a UNIX or Linux variant host operating system. The Xcode project file sqlcipher.xcodeproj takes care of the configure step for you, in the amalgamation target, which has a Run Script build phase.


Thank you @wgray for replying, I executed this in terminal
git clone

now sqlcipher is in root dir of my app


  1. Opened my project in Xcode added sqlcipher.xcodeproj to my main project
    note: sqlite3.c is shown in red colour
  2. Removed libsqlite3.0.dyll file. added target and link binaries, changed other c flag and header search paths
  3. Executed the main project Build fails after showing this

but it does not show any error.

I even downloaded zip file from sqlcipher mentioned by developer notes in his comments here but same thing happened.

I even tried the configure way, but it didn’t work.

I am not able to figure out where i made mistake


Managed to solve the problem: Build was failing and sqlite3.c file was red color.

Now I’m stuck here

int testOpen = sqlite3_open([dbPath UTF8String], &database);
char *myerror=nil;

if (testOpen == SQLITE_OK)
    const char* sqlQ = [[NSString stringWithFormat:@"ATTACH DATABASE '%@' AS btldbencrypted KEY 'test123';",dbPath] UTF8String];
    if(sqlite3_exec(database, sqlQ, NULL, NULL, &myerror)!= SQLITE_OK)
        NSLog(@"ATTACH error %s",myerror);
        if(sqlite3_exec(database, "SELECT sqlcipher_export('btldbencrypted');", NULL, NULL, &myerror)!= SQLITE_OK)
            NSLog(@"sqlcipher_export error %s",myerror);
        if(sqlite3_exec(database, "DETACH DATABASE btldbencrypted;", NULL, NULL, &myerror)!= SQLITE_OK)
            NSLog(@"DETACH error %s",myerror);
return testOpen; 


dbpath is full path to the db: /Users/btlmac/Library/Developer/CoreSimulator/Devices/8706D08E-9AC0-4251-81FC-50CFBA778878/data/Containers/Data/Application/0243F4F4-E324-4518-84F6-A4C22FAEB00D/Documents/testbtldb.sqlite

error i’m getting is:

2015-10-28 12:55:32.089 test[69239:437438] ATTACH error file is encrypted or is not a database

it is not even creating encrypted db in the specified path. i.e Attach command is not creating db btldbencrypted.sqlite
Note: dbpath contains path to the unencrypted db.


Hello @guptag

You can not use dbPath as the path to attach a database as that is already the open database, you must export into a different file. The sqlcipher_export(…) documentation provides some examples showing the conversion process.


Hi @developernotes

Thanks for your help. Now I am able to encrypt the db, later fetch the data and all.

I didn’t understand why is this query required?

"SELECT count(*) FROM sqlite_master;" 

in sqlite3_exec function?

It is used to check if the key is correct or not. But how does it check? For my db that query returns 13.

I even commented sqlite3_exec function part nothing changed, I was still able to access db and even if I provide wrong key it worked.


Hello @guptag

Querying the database once a key has been provided forces the library to attempt to decrypt a portion of the database, which will verify whether the key is correct. The sqlite_master table will always be present. We are glad to hear your application is working now.


Hi @developernotes

Thank you for explanation.

I am making an iPad app which uses sqlcipher. If in future I plan to submit my app on Appstore, then do I have to submit application to DOC mentioning about encryption I’m using in my app as per the process mentioned here?


Hello @guptag

You can find our latest recommendations on that topic here.


Thank you @developernotes