添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

"file is encrypted or is not a database" after executing "pragma cipher_migrate" #233

@authurlan

Description

Expected Behavior

Access the encrypted database successfully.

Actual Behavior

Returned error with "file is encrypted or is not a database".

Steps to Reproduce

  • Use sqlcipher v2.x.x, create a database, set the key contains 'zero' byte, like x'3f2ae1c00a7ba5a8bf00fa7ac10da18e493065fc21c6769ff1bcdd1ce5366aeb'.
  • Upgrade sqlcipher to v3.x.x, reopen the database, set the key used at step one, execute "pragma cipher_migrate";
  • Reopen the database and set the key again, and do some query, then the error will be printed.
  • My founds

  • After doing "pragma cipher_migrate", the key is truncated, which becomes x'3f2ae1c00a7ba5a8bf'.
  • After checking the code, I think the cause is at line 1055 of crypto_impl.c(master branch)
    char *attach_command = sqlite3_mprintf("ATTACH DATABASE '%s-migrated' as migrate KEY '%q';", db_filename, key);
  • SQLCipher version: Upgrade from v2.2.1 to v3.3.1.
    I had tried to fix, but my patch not worked. Thanks for help.