Transition from cipher 2.0 to 3.0 fails. Error 26 on attempt to read

萝らか妹 提交于 2020-01-05 04:39:10

问题


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.


回答1:


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);
}


来源:https://stackoverflow.com/questions/21682940/transition-from-cipher-2-0-to-3-0-fails-error-26-on-attempt-to-read

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!