1

I've used sqlcipher for 2 years. Yesterday I've upgraded to version 3.0.1 and tried to compile sqlcipher including arm64.

If I install new version of my app I can use new cipher lib without any problems. But when I try to upgrade my previous version with DB made with sqlcipher 2.0 I get error 26.

It seems that new cipher can't decrypt my DB.

Also I tried to compile without arm64 support. The same problem.

malex
  • 9,874
  • 3
  • 56
  • 77

1 Answers1

2

I've solved my problem by using

PRAGMA cipher_migrate 

which help to migrate from older DB structures to sqlcipher 3.0 (Details).

It must be executed right after setting the key.

If you want to read old DB (1.X/2.X) with new sqlcipher 3.0 use

PRAGMA kdf_iter = 4000

to set old value for kdf_iter. Now it equals 64,000 (Details)

In terms of lib sqlite db connection looks as follows:

int errorCode = SQLITE_ERROR;
sqlite3 *database = NULL;       
errorCode = sqlite3_open_v2(path, &database, SQLITE_OPEN_READWRITE, NULL);

if (errorCode == SQLITE_OK) {
    errorCode = sqlite3_key(database, key, (int)strlen(key));
}
if (errorCode == SQLITE_OK) {            
    errorCode = sqlite3_exec(database, "PRAGMA kdf_iter = 4000", NULL, NULL, NULL);
}
malex
  • 9,874
  • 3
  • 56
  • 77
  • I'd like to know the specific coding sample. the sample with FMDB is much better for me. – cafedeichi Nov 21 '14 at 01:29
  • @cafedeichi, please look edited answer. It is in terms of pure C sqlite API. I think it is not difficult to insert it in FMDB. – malex Nov 21 '14 at 01:38
  • Seems like i dunno anything about it yet. although i tried to do the same way with FMDB as you have shown, it didn't work. (http://stackoverflow.com/questions/27036546/migrating-sqlcipher-ver-2-x-db-to-ver-3-x-using-by-fmdb) Thx a lot anyway :) – cafedeichi Nov 21 '14 at 03:50
  • @cafedeichi, please see my suggestion in your question. – malex Nov 21 '14 at 03:58
  • @beardedbeast, what do you mean? The full code example is in the text above. – malex May 10 '16 at 18:19