Sqlcipher.a linking problem in Xcode 4.4 and iOs 5.1

902 views
Skip to first unread message

AKD

unread,
Aug 16, 2012, 2:04:04 AM8/16/12
to sqlc...@googlegroups.com
Hi,
I am able to build the openssl using my xcode 4.4 but when i am trying to add the code to encrypt the data (using sample code) and trying to create build for simulator and device i am getting lot of errors. in Simulator i am getting following errors.

Undefined symbols for architecture i386:

  "_EVP_CIPHER_CTX_cleanup", referenced from:

      _sqlcipher_page_cipher in libsqlcipher.a(sqlite3.o)

  "_EVP_CIPHER_CTX_set_padding", referenced from:

      _sqlcipher_page_cipher in libsqlcipher.a(sqlite3.o)

  "_EVP_CIPHER_block_size", referenced from:

      _sqlcipher_codec_ctx_set_cipher in libsqlcipher.a(sqlite3.o)

  "_EVP_CIPHER_iv_length", referenced from:

      _sqlcipher_codec_ctx_set_cipher in libsqlcipher.a(sqlite3.o)

  "_EVP_CIPHER_key_length", referenced from:

      _sqlcipher_codec_ctx_set_cipher in libsqlcipher.a(sqlite3.o)

  "_EVP_CipherFinal", referenced from:

      _sqlcipher_page_cipher in libsqlcipher.a(sqlite3.o)

  "_EVP_CipherInit", referenced from:

      _sqlcipher_page_cipher in libsqlcipher.a(sqlite3.o)

  "_EVP_CipherUpdate", referenced from:

      _sqlcipher_page_cipher in libsqlcipher.a(sqlite3.o)

  "_EVP_MD_size", referenced from:

      _sqlcipher_codec_ctx_set_cipher in libsqlcipher.a(sqlite3.o)

  "_EVP_get_cipherbyname", referenced from:

      _sqlcipher_codec_ctx_set_cipher in libsqlcipher.a(sqlite3.o)

      _sqlcipher_activate in libsqlcipher.a(sqlite3.o)

  "_EVP_sha1", referenced from:

      _sqlcipher_codec_ctx_set_cipher in libsqlcipher.a(sqlite3.o)

      _sqlcipher_page_hmac in libsqlcipher.a(sqlite3.o)

  "_HMAC_CTX_cleanup", referenced from:

      _sqlcipher_page_hmac in libsqlcipher.a(sqlite3.o)

  "_HMAC_CTX_init", referenced from:

      _sqlcipher_page_hmac in libsqlcipher.a(sqlite3.o)

  "_HMAC_Final", referenced from:

      _sqlcipher_page_hmac in libsqlcipher.a(sqlite3.o)

  "_HMAC_Init_ex", referenced from:

      _sqlcipher_page_hmac in libsqlcipher.a(sqlite3.o)

  "_HMAC_Update", referenced from:

      _sqlcipher_page_hmac in libsqlcipher.a(sqlite3.o)

  "_OPENSSL_add_all_algorithms_noconf", referenced from:

      _sqlcipher_activate in libsqlcipher.a(sqlite3.o)

  "_PKCS5_PBKDF2_HMAC_SHA1", referenced from:

      _sqlcipher_cipher_ctx_key_derive in libsqlcipher.a(sqlite3.o)

  "_RAND_bytes", referenced from:

      _sqlcipher_random in libsqlcipher.a(sqlite3.o)

ld: symbol(s) not found for architecture i386

clang: error: linker command failed with exit code 1 (use -v to see invocation)


and when trying to build for device i am getting following errors

Undefined symbols for architecture armv7:

  "_HMAC_Init_ex", referenced from:

      _sqlcipher_page_hmac in libsqlcipher.a(sqlite3.o)

  "_EVP_CIPHER_CTX_set_padding", referenced from:

      _sqlcipher_page_cipher in libsqlcipher.a(sqlite3.o)

  "_EVP_CIPHER_key_length", referenced from:

      _sqlcipher_codec_ctx_set_cipher in libsqlcipher.a(sqlite3.o)

  "_EVP_get_cipherbyname", referenced from:

      _sqlcipher_codec_ctx_set_cipher in libsqlcipher.a(sqlite3.o)

      _sqlcipher_activate in libsqlcipher.a(sqlite3.o)

  "_OPENSSL_add_all_algorithms_noconf", referenced from:

      _sqlcipher_activate in libsqlcipher.a(sqlite3.o)

  "_EVP_CIPHER_CTX_cleanup", referenced from:

      _sqlcipher_page_cipher in libsqlcipher.a(sqlite3.o)

  "_EVP_sha1", referenced from:

      _sqlcipher_codec_ctx_set_cipher in libsqlcipher.a(sqlite3.o)

      _sqlcipher_page_hmac in libsqlcipher.a(sqlite3.o)

  "_PKCS5_PBKDF2_HMAC_SHA1", referenced from:

      _sqlcipher_cipher_ctx_key_derive in libsqlcipher.a(sqlite3.o)

  "_EVP_CipherUpdate", referenced from:

      _sqlcipher_page_cipher in libsqlcipher.a(sqlite3.o)

  "_HMAC_CTX_init", referenced from:

      _sqlcipher_page_hmac in libsqlcipher.a(sqlite3.o)

  "_EVP_CIPHER_block_size", referenced from:

      _sqlcipher_codec_ctx_set_cipher in libsqlcipher.a(sqlite3.o)

  "_EVP_CipherFinal", referenced from:

      _sqlcipher_page_cipher in libsqlcipher.a(sqlite3.o)

  "_EVP_CipherInit", referenced from:

      _sqlcipher_page_cipher in libsqlcipher.a(sqlite3.o)

  "_HMAC_CTX_cleanup", referenced from:

      _sqlcipher_page_hmac in libsqlcipher.a(sqlite3.o)

  "_HMAC_Update", referenced from:

      _sqlcipher_page_hmac in libsqlcipher.a(sqlite3.o)

  "_EVP_MD_size", referenced from:

      _sqlcipher_codec_ctx_set_cipher in libsqlcipher.a(sqlite3.o)

  "_RAND_bytes", referenced from:

      _sqlcipher_random in libsqlcipher.a(sqlite3.o)

  "_EVP_CIPHER_iv_length", referenced from:

      _sqlcipher_codec_ctx_set_cipher in libsqlcipher.a(sqlite3.o)

  "_HMAC_Final", referenced from:

      _sqlcipher_page_hmac in libsqlcipher.a(sqlite3.o)

ld: symbol(s) not found for architecture armv7

clang: error: linker command failed with exit code 1 (use -v to see invocation)


I have carefully followed all the steps explain in the official site (http://sqlcipher.net/ios-tutorial/).
I am using Xcode 4.4 with ios sdk 5.1.

Stephen Lombardo

unread,
Aug 17, 2012, 12:17:58 AM8/17/12
to sqlc...@googlegroups.com
AKD,

Do you have the OpenSSL-xcode "Crypto" target configured as a build dependency? And, is libcrypto.a setup as a linked library? Issues with either one of those settings could cause this problem in the community edition build process. If those are both setup properly, it would be helpful for you to examile the build log to ensure that OpenSSL is actually being compiled successfuly.

Cheers,
Stephen

AKD

unread,
Aug 20, 2012, 5:03:14 AM8/20/12
to sqlc...@googlegroups.com
Thanks Stephen,
i have removed my project and create a new one and follow all the steps to configure the sqlcipher. now i am able to build and run my application. Now  I am trying to verify the encryption of database using the hexdump command tool on saved file of DB in my application document directory of the ios simulator 5.1. but it seems no encryption applied in the saved db file. How can i verify whether my DB is encrypted or not. 

Thanks in advance

Stephen Lombardo

unread,
Aug 20, 2012, 11:23:39 AM8/20/12
to sqlc...@googlegroups.com
AKD,

When you create the database, are you calling sqlite3_key to give it non-empty key data immediately after opening? If you don't provide a key, SQLCipher will create a standard SQLite database.

Cheers,
Stephen

AKD

unread,
Aug 21, 2012, 1:04:38 AM8/21/12
to sqlc...@googlegroups.com
HI Stephen,
i have an existing DB which i have added in my app and then when app start very first time i am copying the DB from app bundle to Document directory of app. after that i am using the following method to open the DB. but it seems DB is not getting encrypted. 

- (void) openDatabaseConnection

{

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *path = [documentsDirectory stringByAppendingPathComponent:APPDB];

// Open the database. The database was prepared outside the application.

if (sqlite3_open([path UTF8String], &dataBaseConnection) == SQLITE_OK)

{

        const char* key = [@"BIGSecret" UTF8String];

        sqlite3_key(dataBaseConnection, key, strlen(key));

NSLog(@"Database Successfully Opened :)");

        if (sqlite3_exec(dataBaseConnection, (const char*) "SELECT count(*) FROM sqlite_master;", NULL, NULL, NULL) == SQLITE_OK) {

            NSLog(@"password correct");

        } else {

            NSLog(@"password Wrong");

        }

}

else

{

NSLog(@"Error in opening database :(");

}

}

APPDB is the name of my database file.


Thanks
AKD

Nick Parker

unread,
Aug 21, 2012, 8:51:04 AM8/21/12
to sqlc...@googlegroups.com
Hi AKD,

The function sqlite3_key is an alternative method to invoking the PRAGMA key command, you can not run this command on an unencrypted database to encrypt it with a key.  The function sqlcipher_export [1] can be used to migrate from a non-encrypted database to an encrypted database.


Nick Parker

AKD

unread,
Aug 22, 2012, 1:20:13 AM8/22/12
to sqlc...@googlegroups.com
Thanks Nick,
its means we can not encrypt our existing DB (within app bundle) through programmatically and we must encrypt DB first and then add the encrypted DB with our application right?
I tried to use the 'sqlcipher_export' but getting the error 'no such function: sqlcipher_export', Am i missing anything?

AKD

Nick Parker

unread,
Aug 22, 2012, 9:01:34 AM8/22/12
to sqlc...@googlegroups.com
Hi AKD,

No, you can certainly can encrypt a standard SQLite database using SQLCipher and you would actually use the sqlcipher_export function to do so.  The export function will actually create a new database file.  The sqlcipher_export function was added to the 2.0 version of SQLCipher so you will want to make sure you have the latest version of the library to use that.

Nick Parker
Reply all
Reply to author
Forward
0 new messages