Encrypted Db is not opening

I have downloaded the source code from the above link and compiled for IOS.
Placed generated libsqlitecipher_debug.a, libsqlitecipher.a on the below path:
/Users/pallavituteja/Qt/5.11.1/ios/plugins/sqldrivers

Now when i compile test application with the following code:

#ifdef Q_OS_IOS

include <QtPlugin>

Q_IMPORT_PLUGIN(SqliteCipherDriverPlugin)

#endif

#define CONNECTION_FAILED -1

int main(int argc, char *argv)

{

QCoreApplication app(argc, argv);

Q_UNUSED(app);

qDebug() << QSqlDatabase::drivers();

QString dir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);

QString DB_FILE_PATH = dir + "/test_1.db";

qDebug() << "DB File Path is:" << DB_FILE_PATH;

QSqlDatabase dbconn = QSqlDatabase::addDatabase("SQLITECIPHER");

dbconn.setDatabaseName(DB_FILE_PATH);

dbconn.setPassword("test");

dbconn.setConnectOptions("QSQLITE_CREATE_KEY");

//dbconn.setConnectOptions("QSQLITE_USE_CIPHER=sqlcipher; QSQLITE_ENABLE_REGEXP");

if (!dbconn.open()) {

qDebug() << "Can not open connection: " << dbconn.lastError().driverText();

exit(CONNECTION_FAILED);

}

QSqlQuery query;

query.exec("create table mapping (id int, name varchar)");

query.exec(“insert into mapping values (1, ‘AAA’)”);

query.exec(“insert into mapping values (2, ‘BBB’)”);

query.exec(“insert into mapping values (3, ‘CCC’)”);

query.exec(“insert into mapping values (4, ‘DDD’)”);

query.exec(“insert into mapping values (5, ‘EEE’)”);

query.exec(“insert into mapping values (6, ‘FFF’)”);

query.exec(“insert into mapping values (7, ‘GGG’)”);

query.exec(“select * from mapping where name regexp ‘(a|A)$’”);

if (query.next()) {

qDebug() << "Regexp result: " << query.value(0).toInt() << ": " << query.value(1).toString();

} else {

qDebug() << "This plugin does not support regexp.";

}

qDebug() << "----------" << endl;

query.exec("select id, name from mapping");

while (query.next()) {

qDebug() << query.value(0).toInt() << ": " << query.value(1).toString();

}

qDebug() << "----------" << endl;

query.exec(“update mapping set name=‘ZZZ’ where id=1”);

query.exec("select id, name from mapping");

while (query.next()) {

qDebug() << query.value(0).toInt() << ": " << query.value(1).toString();

}

qDebug() << "----------" << endl;

query.exec("delete from mapping where id=4");

query.exec("select id, name from mapping");

while (query.next()) {

qDebug() << query.value(0).toInt() << ": " << query.value(1).toString();

}

query.exec("drop table mapping");

dbconn.close();

return 0;

}

Encrypted DB is getting created But i am not able to open it.
Every time it prompts for the password even if i am giving correct one every time.

Hello @pallavi - The plugin you references is not part of the SQLCipher project. It appears to use a completely different encryption plugin / codec. I would suggest opening an issue on their GitHub Issues Page.

i have downloaded sqlcipher code.
Where to find sample for how to build it for Ios with QT.
Is openssl is already integrated in latest code ?

Hello @pallavi - we don’t directly support QT plugin. There are a variety of 3rd party tutorials that appear in Google searches for QT and SQLCipher, it might be worthwhile to take a look at those. If you just need an iOS build of SQLCipher itself for static linking, we do offer that through our Commercial Edition licensing, including a free trial: https://www.zetetic.net/sqlcipher/buy/

So if i want to use SqlCipher with QT I have to build SqlCipher with OpenSSL ?

Hello @pallavi

SQLCipher does not implement it’s own cryptographic primitives, so you would need to build SQLCipher with a registered crypto provider. We include providers for OpenSSL, CommonCrypto, and libtomcrypt, however OpenSSL is the default. The provider defers operations to the bundled crypto library itself. If you use OpenSSL, you would need to build it for your target platform.

Hi,

I am trying to build sqlcipher with openssl on mac os with the below command:

./configure --prefix=/Users/pallavituteja/SourceCodeCompile/sqlcipher-install --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC -I/Users/pallavituteja/SourceCodeCompile/openssl_install/include/" LDFLAGS="/Users/pallavituteja/SourceCodeCompile/openssl_install/lib/libcrypto.a"

its giving following error:

*** Warning: Linking the shared library libsqlcipher.la against the

*** static library /Users/pallavituteja/SourceCodeCompile/openssl_install/lib/libcrypto.a is not portable!

libtool: link: rm -fr .libs/libsqlcipher.0.dylib .libs/libsqlcipher.a .libs/libsqlcipher.dylib

libtool: link: gcc -dynamiclib -o .libs/libsqlcipher.0.dylib .libs/sqlite3.o /Users/pallavituteja/SourceCodeCompile/openssl_install/lib/libcrypto.a -lcrypto -install_name /Users/pallavituteja/SourceCodeCompile/sqlcipher-install/lib/libsqlcipher.0.dylib -compatibility_version 9 -current_version 9.6 -Wl,-single_module

libtool: link: (cd “.libs” && rm -f “libsqlcipher.dylib” && ln -s “libsqlcipher.0.dylib” “libsqlcipher.dylib”)

libtool: link: ar cru .libs/libsqlcipher.a /Users/pallavituteja/SourceCodeCompile/openssl_install/lib/libcrypto.a sqlite3.o

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive member: .libs/libsqlcipher.a(libcrypto.a) fat file for cputype (12) cpusubtype (9) is not an object file (bad magic number)

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar: internal ranlib command failed

make: *** [libsqlcipher.la] Error 1

any idea of above error ?

Hello @pallavi - Off hand, it looks like libcrypto.a is not being properly built and linked. Unfortunately, we can’t really provide further advise on what the specific problem with your OpenSSL build could be.

Hi,

Which openssl version u support with SqlCipher ?

@pallavi - SQLCipher should work with any recently modern version of OpenSSL including 1.0.2* and 1.1.0* and 1.1.1. However, to be clear, we don’t provide support or instructions for building OpenSSL itself.

Thanks @sjlombardo
I have applied for free version of commercial edition for SQLCipher Mac os, Ios and android.
Is it FIPS complaint?

If i will purchase Enterprise edition then will i be getting samples for how to use SqlCiher in QT ?
and will that be FIPS Complaint?

Hello @pallavi - no, Community and Commercial Edition packages do not offer FIPS 140-2 validated cryptographic modules. Those are only available through the SQLCipher Enterprise program as an optional feature. Such specialized packages are built using a dedicated FIPS 140-2 validated cryptographic module, linked directly into the SQLCipher library, that ensures the same library is used on all deployments, and also facilitates the self test requirements.

If you have further questions about SQLCipher Enterprise and FIPS 140-2, please feel free to touch base with us at support@zetetic.net.