Implicit declaracion of function 'sqlite3_key'

1,668 views
Skip to first unread message

Jorge Ferrando

unread,
May 12, 2011, 7:48:06 AM5/12/11
to sqlc...@googlegroups.com
Hi!

I'm trying to use sqlcipher on my iPhone app. I've followed the documentation and I could compile and execute SQLCipherSpeed so everything is well configured.

I had my App already working with regular sqlite. I followed the instructions to add sqlcipher to my project and everything compiled right. But I'm having a warning:

Implicit declaracion of function 'sqlite3_key'

I guess it's because the project is still using regular sqlite instead of sqlitecipher. I removed the libsqlite from the frameworks but it still gives the same warning and it fails on executing the test: "incorrect password"

Any ideas??

Thank you.

Jorge 


Billy Gray

unread,
May 12, 2011, 10:08:06 AM5/12/11
to sqlc...@googlegroups.com
On Thu, May 12, 2011 at 7:48 AM, Jorge Ferrando <jfer...@cc.upv.es> wrote:

I had my App already working with regular sqlite. I followed the instructions to add sqlcipher to my project and everything compiled right. But I'm having a warning:

Implicit declaracion of function 'sqlite3_key'


Have you updated the Header Search Paths setting on your target? I think this might resolve the warning you're getting. 

 
I guess it's because the project is still using regular sqlite instead of sqlitecipher. I removed the libsqlite from the frameworks but it still gives the same warning and it fails on executing the test: "incorrect password"


Well, it's true that you don't want to link in the reqular libsqlite framework. However, you should have libsqlcipher.a listed as a dependency on your target, is that the case?

Cheers,
Billy

Michael Stephenson

unread,
May 12, 2011, 11:34:58 AM5/12/11
to sqlc...@googlegroups.com

Also, SQLITE_HAS_CODEC should be defined, otherwise the sqlite3.h header will not declare sqlite3_key, etc.

Billy Gray

unread,
May 12, 2011, 11:46:54 AM5/12/11
to sqlc...@googlegroups.com
On Thu, May 12, 2011 at 11:34 AM, Michael Stephenson <domeh...@gmail.com> wrote:

Also, SQLITE_HAS_CODEC should be defined, otherwise the sqlite3.h header will not declare sqlite3_key, etc.



Indeed. It's a must if you're going to run the build yourself. If you are using the XCode project provided in the sqlcipher repo, this flag is already present on build settings for the sqlcipher library target:


Cheers,
Billy

Jorge

unread,
May 13, 2011, 2:32:32 AM5/13/11
to SQLCipher Users
I'm using the Xcode project for openssl.

I'd swear I set the header paths but when I rechecked they weren't
there. So I set them again, clean al targets, rebuilt and...

Same warning: "Implicit declaracion of function 'sqlite3_key' "

On May 12, 5:46 pm, Billy Gray <wg...@zetetic.net> wrote:
> On Thu, May 12, 2011 at 11:34 AM, Michael Stephenson
> <domehead...@gmail.com>wrote:
>
> >  Also, SQLITE_HAS_CODEC should be defined, otherwise the sqlite3.h header
> > will not declare sqlite3_key, etc.
>
> Indeed. It's a must if you're going to run the build yourself. If you are
> using the XCode project provided in the sqlcipher repo, this flag is already
> present on build settings for the sqlcipher library target:
>
> https://github.com/sjlombardo/sqlcipher/blob/master/sqlcipher.xcodepr...
>
> Cheers,
> Billy

Cocoa71

unread,
May 13, 2011, 8:37:46 AM5/13/11
to sqlc...@googlegroups.com
Hello,


All is working fine with :
sqlite3_exec(baseLexicaleGeneraleFR, "PRAGMA key = 'BIGsecret'", NULL, NULL, NULL);

Or with :
const char* key = [@"BIGSecret" UTF8String];
sqlite3_key(baseLexicaleGeneraleFR, key, strlen(key));

But with this 2nd method there is this warning.


Other question : In the application distribution, we don't need to include the libsqlcipher.a ?? My release tests show the application is working without. Is it normal ?


Thanks,
Eddy

Michael Stephenson

unread,
May 13, 2011, 9:16:53 AM5/13/11
to sqlc...@googlegroups.com
Did you make sure that SQLITE_HAS_CODEC is defined? I'm not talking about
having it defined when building SqlCipher, I'm talking about having it
defined in YOUR app where you include sqlite3.h.

I've no experience with XCode, but "implicit declaration" sounds to me like
the function is defined but no declared.

An excerpt from sqlite3.h (note the #ifdef on the first line):

#ifdef SQLITE_HAS_CODEC
/*
** Specify the key for an encrypted database. This routine should be
** called right after sqlite3_open().
**
** The code to implement this API is not available in the public release
** of SQLite.
*/
SQLITE_API int sqlite3_key(
sqlite3 *db, /* Database to be rekeyed */
const void *pKey, int nKey /* The key */
);

-----Original Message-----
From: sqlc...@googlegroups.com [mailto:sqlc...@googlegroups.com] On

Stephen Lombardo

unread,
May 13, 2011, 11:11:01 AM5/13/11
to sqlc...@googlegroups.com
Hi Eddy,

As Michael mentioned in this discussion (http://groups.google.com/group/sqlcipher/browse_thread/thread/fb842d2116d9c70f), you'll want to define SQLITE_HAS_CODEC in your application build settings, so that the sqlite3_key function is included in the sqlite3.h header. 

With regard to your second question, there is no need to distribute libsqlcipher.a since it is statically linked to your application.

Cheers,
Stephen

Cocoa71

unread,
May 13, 2011, 7:53:50 PM5/13/11
to sqlc...@googlegroups.com
Ok, I make the define and now it's all right :)

Thanks for your help

Jorge

unread,
May 14, 2011, 2:03:25 AM5/14/11
to SQLCipher Users
Maybe it's something obvious but, how and where should I define
SQLITE_HAS_CODEC?

If it's the case, I think that should be in the official
documentation.

Thanks again.

On May 13, 3:16 pm, "Michael Stephenson" <domehead...@gmail.com>
wrote:
Message has been deleted

Jorge Ferrando

unread,
May 14, 2011, 5:54:27 AM5/14/11
to sqlc...@googlegroups.com
Thank you very much Eddy

I'll give it a try on Monday and I'll post the results in the group

El 14/05/2011, a las 11:52, Cocoa71 <edd...@gmail.com> escribió:

> Hello Jorge,
>
> the setting is in your project build options, in "Other C Flags". See the image with this post.
>
> Eddy
>
> [IMG]http://img713.imageshack.us/img713/9818/sqlciphersqlitehascodec.png[/IMG]
>

Cocoa71

unread,
May 14, 2011, 5:58:36 AM5/14/11
to sqlc...@googlegroups.com
Hello Jorge,

the setting is in your project build options, in "Other C Flags". See the image : http://img713.imageshack.us/i/sqlciphersqlitehascodec.png/

We can see a reference in this part of the doc : http://sqlcipher.net/documentation

But not in the iOS tutorial. I agree to adding in the iOS tutorial this reference. 

Regards,
Eddy

Stephen Lombardo

unread,
May 15, 2011, 5:29:03 PM5/15/11
to sqlc...@googlegroups.com
Hi Guys,

We're in the process of moving the sqlcipher site to a new host. I'll make a note to update the tutorial as soon as that's complete.

Cheers,
Stephen

Jorge Ferrando

unread,
May 16, 2011, 4:21:11 AM5/16/11
to sqlc...@googlegroups.com
const char* key = [@"BIGSecret" UTF8String];
sqlite3_key(handle, key, strlen(key));
if (sqlite3_exec(handle, (const char*) "SELECT count(*) FROM sqlite_master;", NULL, NULL, NULL) == SQLITE_OK) {
} else {
NSLog(@"%@", @"incorrect password");

Jorge Ferrando

unread,
May 16, 2011, 4:23:04 AM5/16/11
to sqlc...@googlegroups.com
Now the warning disappeared but I'm getting "incorrect password" when running sample code

const char* key = [@"BIGSecret" UTF8String];
sqlite3_key(handle, key, strlen(key));
if (sqlite3_exec(handle, (const char*) "SELECT count(*) FROM sqlite_master;", NULL, NULL, NULL) == SQLITE_OK) {
} else {
NSLog(@"%@", @"incorrect password");
}


On Sun, May 15, 2011 at 11:29 PM, Stephen Lombardo <sjlom...@zetetic.net> wrote:
Hi Guys,

We're in the process of moving the sqlcipher site to a new host. I'll make a note to update the tutorial as soon as that's complete.

Cheers,
Stephen

Billy Gray

unread,
May 16, 2011, 10:14:27 AM5/16/11
to sqlc...@googlegroups.com
Jorge,

Try to work with the NSString pointer type for your SQL strings instead of const char pointers, and just convert them when necessary with the UTF8String method, like so:

NSString *countSql = @"SELECT COUNT(*) FROM sqlite_master;";
NSString *key = @"BIGSecret";

sqlite3_key(handle, [key UTF8String]);
sqlite3_exec(handle, [countSql UTF8String], NULL, NULL, NULL); // etc

Cheers,
Billy
--
Team Zetetic
http://zetetic.net

Jorge Ferrando

unread,
May 16, 2011, 10:19:12 AM5/16/11
to sqlc...@googlegroups.com
Tried that way but same result:

Error: 11 "database disk image is malformed"

Billy Gray

unread,
May 16, 2011, 10:28:08 AM5/16/11
to sqlc...@googlegroups.com
Is this related to the other thread you've started, where you are trying to set a key on a plain-text sqlite database using rekey?

That won't work, you can't use sqlite3_rekey to set a key on an unencrypted database. Sorry if it's not clear enough in the documentation, but it's been covered quite a bit here in past posts to the list, I suggest you take a quick look at the recent archives. You must attach the plain text database to your new encrypted database, and copy your schema and data into the new encrypted database. 

Cheers,
Billy

Jorge Ferrando

unread,
May 16, 2011, 10:32:06 AM5/16/11
to sqlc...@googlegroups.com
Certainly it's really confusing cause this is what documentation shows:

"Now that the SQLCipher library is incorporated into the project you can start using the system immediately. Telling SQLCipher to encrypt a database is as easy as opening a database and using the sqlite3_key function, or PRAGMA key"."

I'll try to follow the steps you point.

Thank you.

Michael Stephenson

unread,
May 16, 2011, 10:49:10 AM5/16/11
to sqlc...@googlegroups.com

You can’t use sqlite3_rekey to encrypt an existing plain database.  Generally, sqlite3_rekey can only be used to change the key or certain encryption parameters on an already encrypted database.

 

Search the mailing list archive for discussions on this topic and steps needed for encrypting an existing plain database or decrypting an existing encrypted database.  The new beta version of SqlCipher makes this possible following a specific set of steps (I think this works, can’t remember 100%).

 

From: sqlc...@googlegroups.com [mailto:sqlc...@googlegroups.com] On Behalf Of Jorge Ferrando


Sent: Monday, May 16, 2011 10:19 AM
To: sqlc...@googlegroups.com

Billy Gray

unread,
May 16, 2011, 10:50:06 AM5/16/11
to sqlc...@googlegroups.com
On Mon, May 16, 2011 at 10:32 AM, Jorge Ferrando <jfer...@cc.upv.es> wrote:
Certainly it's really confusing cause this is what documentation shows:

"Now that the SQLCipher library is incorporated into the project you can start using the system immediately. Telling SQLCipher to encrypt a database is as easy as opening a database and using the sqlite3_key function, or PRAGMA key"."

The section on rekey does attempt to make this clearer, and there are some example steps in the attach section below it that help to illustrate the solution:


Please let me know if this helps. We'll try to adjust for the confusion in the next iteration of the documentation, we're about to move the site to a new host and we'll add this to the list of adjustments to make.

Cheers,
Billy

Stephen Lombardo

unread,
May 16, 2011, 11:55:25 AM5/16/11
to sqlc...@googlegroups.com
Jorge,

You might also be interested to look at the v2beta branch for the upcoming SQLCipher version 2. This includes an experimental sqlcipher_export function which can be used to effectively encrypt an unencrypted database to an attached encrypted database. More details can be found here:


Cheers,
Stephen

Jorge Ferrando

unread,
May 17, 2011, 2:56:38 AM5/17/11
to sqlc...@googlegroups.com
I downloaded and compiled the beta version 2 and tryed what I read in that post and this is what I'm getting:

sqlite> SELECT sqlcipher_export('encrypted');
Error: no such function: sqlcipher_export

Stephen Lombardo

unread,
May 17, 2011, 11:51:49 AM5/17/11
to sqlc...@googlegroups.com
Hi Jorge,

Are you sure you checked out your git repository to the v2beta branch? In your local repository try running "git branch" and make sure that v2beta is starred, i.e.

zenzic:sjlombardo sqlcipher:v2beta$ git branch
  ditto
  master
  sqlite-release
* v2beta
  
Cheers,
Stephen

Jorge

unread,
May 18, 2011, 2:31:12 AM5/18/11
to SQLCipher Users
I'm downloading it with chrome, selecting the branch v2beta

On May 17, 5:51 pm, Stephen Lombardo <sjlomba...@zetetic.net> wrote:
> Hi Jorge,
>
> Are you sure you checked out your git repository to the v2beta branch? In your local repository try running "git branch" and make sure that v2beta is starred, i.e.
>
> zenzic:sjlombardo sqlcipher:v2beta$ git branch
> ditto
> master
> sqlite-release
> * v2beta
>
> Cheers,
> StephenOn Tuesday, May 17, 2011 at 2:56 AM, Jorge Ferrando wrote:
>
> I downloaded and compiled the beta version 2 and tryed what I read in that post and this is what I'm getting:
>
>
>
>
>
>
>
>
>
> > sqlite> SELECT sqlcipher_export('encrypted');
> > Error: no such function: sqlcipher_export
>
> > On Mon, May 16, 2011 at 5:55 PM, Stephen Lombardo <sjlomba...@zetetic.net> wrote:
> > > Jorge,
>
> > > You might also be interested to look at the v2beta branch for the upcoming SQLCipher version 2. This includes an experimental sqlcipher_export function which can be used to effectively encrypt an unencrypted database to an attached encrypted database. More details can be found here:
>
> > >http://groups.google.com/group/sqlcipher/msg/76d5b03426419761
>
> > > Cheers,
> > > Stephen
> > > On Monday, May 16, 2011 at 10:50 AM, Billy Gray wrote:

Jorge

unread,
May 18, 2011, 2:42:05 AM5/18/11
to SQLCipher Users
Ok, I did it in the command line. Now getting a different error:

./sqlite3 database.db
SQLite version 3.7.6.2
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> ATTACH DATABASE 'encrypted.db' AS encrypted KEY 'key';
dyld: lazy symbol binding failed: Symbol not found:
_EVP_get_cipherbyname
Referenced from: /Users/jorfermo/Downloads/temp/sqlcipher/.libs/
libsqlite3.0.dylib
Expected in: flat namespace

dyld: Symbol not found: _EVP_get_cipherbyname
Referenced from: /Users/jorfermo/Downloads/temp/sqlcipher/.libs/
libsqlite3.0.dylib
Expected in: flat namespace

Trace/BPT trap

Stephen Lombardo

unread,
May 18, 2011, 10:22:24 AM5/18/11
to sqlc...@googlegroups.com
Jorge,

When you configure on the command line you need to include LDFLAGS="-lcrypto" to dynamically link against libcrypto, i.e.

  ./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="-lcrypto"

Cheers,
Stephen

Jorge Ferrando

unread,
May 19, 2011, 3:10:12 AM5/19/11
to sqlc...@googlegroups.com
Thanks again Stephen.

I managed to compile the v2beta and encrypt the database but then it didn't work on the iPhone App. I guess I should use there the same sqlcipher version.

Finally I just made an script to rebuild the database from scratch using PRAGMA key to encrypt.

Thanks for your help.

Jorge
Reply all
Reply to author
Forward
0 new messages