如何优化SQLcipher性能?

iSi*_*Dev 5 sqlite ios sqlcipher

我使用 SQLCipher 在我的应用程序中加密 sqlite 数据库。一切正常,但我的应用程序在获取数据库期间运行缓慢。我将PRAGMA kdf_iter更改为 4000,但它仍然很慢。加密之前我没有任何问题。

-(NSError *) openDatabase {

    NSError *error = nil; 
    NSString *databasePath = [self getDatabasePath];

    const char *dbpath = [databasePath UTF8String];   
    int result = sqlite3_open_v2 (dbpath, &db , SQLITE_OPEN_READWRITE , NULL);
    if (result == SQLITE_OK) {

        sqlite3_exec(db, [@"PRAGMA kdf_iter = '4000';" UTF8String], NULL, NULL, NULL);
        sqlite3_exec(db, [@"PRAGMA key = 'password'" UTF8String], NULL, NULL, NULL);

        NSLog(@"Password is correct , Database is Activated");
        sqlite3_exec(db, [@"PRAGMA cipher = 'aes-256-cfb';" UTF8String], NULL, NULL, NULL);

    }
    else {
        NSLog(@"Incorrect password!");
    }
    if (result != SQLITE_OK) {
        const char *errorMsg = sqlite3_errmsg(db);
        NSString *errorStr = [NSString stringWithFormat:@"The database could not be opened: %@",[NSString stringWithCString:errorMsg encoding:NSUTF8StringEncoding]];
        error = [self createDBErrorWithDescription:errorStr andCode:kDBFailAtOpen];

    }

    return error;
}
Run Code Online (Sandbox Code Playgroud)

zap*_*aph 0

为什么使用 CFB 模式 (aes-256-cfb) 而不是 CBC?

我不相信硬件加密支持 AES CFB,因此它可能会使用软件加密,这很容易慢 500 倍以上。

来自文档:

SQLCipher 使用 aes-256-cbc 作为默认密码和操作模式。可以更改此设置,但通常不建议这样做