# Upgrading from android-database-sqlcipher to sqlcipher-android

**URL:** <https://discuss.zetetic.net/t/upgrading-from-android-database-sqlcipher-to-sqlcipher-android/6741>\
**Category:** SQLCipher\
**Created:** [September 5, 2024, 1:20pm UTC](https://discuss.zetetic.net/t/upgrading-from-android-database-sqlcipher-to-sqlcipher-android/6741 "2024-09-05T13:20:19Z")\
**Posts on this page:** 6\
**Page:** 3

<div class="post-metadata">

**Author:** ![developernotes](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/developernotes/32/1309_2.png) [@developernotes](https://discuss.zetetic.net/u/developernotes)\
**Post date:** [November 25, 2024, 4:54pm UTC](https://discuss.zetetic.net/t/upgrading-from-android-database-sqlcipher-to-sqlcipher-android/6741/41 "2024-11-25T16:54:11Z")

</div>

Hi @FrozenPyrozen,

Thank you for providing an update on your goals. Since your aim is to maintain compatibility with version 3 database file formats, you can provide the following hook when you open your connection:

```java
SQLiteDatabaseHook hook = new SQLiteDatabaseHook() {
        public void preKey(SQLiteDatabase database) {}
        public void postKey(SQLiteDatabase database) {
          database.execSQL("PRAGMA cipher_compatibility = 3;");
        }
      };

```

If you are getting an error where it fails to open the database (and you can reproduce this locally), it would be best to pull that database off the device/emulator and attempt to access the database file using the SQLCipher shell, or graphical management interface such as DB Browser for SQLite. Would you give that a try and let us know your result?

---

<div class="post-metadata">

**Author:** ![FrozenPyrozen](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/frozenpyrozen/32/2296_2.png) [@FrozenPyrozen](https://discuss.zetetic.net/u/FrozenPyrozen)\
**Post date:** [December 3, 2024, 1:40pm UTC](https://discuss.zetetic.net/t/upgrading-from-android-database-sqlcipher-to-sqlcipher-android/6741/43 "2024-12-03T13:40:46Z")

</div>

Hi, @developernotes

I’ve get db from emulator after we updated newer build with android 14 changes and cipher version, but looks like it didn’t opened, maybe smth wrong with password

 ![image](https://us1.discourse-cdn.com/flex016/uploads/zetetic/original/2X/0/0ab6758ed9d6a76d1942946c3ab125a0294442b7.jpeg)

I’ve added some logging code to see db info, so my `postKey` code looks like this, not sure what encryption settings should I use

 ![image](https://us1.discourse-cdn.com/flex016/uploads/zetetic/original/2X/9/940b03a103e0d11799242d542b1500a80f24e036.png)

---

<div class="post-metadata">

**Author:** ![sjlombardo](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/sjlombardo/32/3_2.png) [@sjlombardo](https://discuss.zetetic.net/u/sjlombardo)\
**Post date:** [December 3, 2024, 1:54pm UTC](https://discuss.zetetic.net/t/upgrading-from-android-database-sqlcipher-to-sqlcipher-android/6741/44 "2024-12-03T13:54:55Z")

</div>

@FrozenPyrozen why don’t you try using the “SQLCipher 3 Defaults” setting in DB Browser for SQLite?

---

<div class="post-metadata">

**Author:** ![FrozenPyrozen](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/frozenpyrozen/32/2296_2.png) [@FrozenPyrozen](https://discuss.zetetic.net/u/FrozenPyrozen)\
**Post date:** [December 4, 2024, 11:07am UTC](https://discuss.zetetic.net/t/upgrading-from-android-database-sqlcipher-to-sqlcipher-android/6741/45 "2024-12-04T11:07:30Z")

</div>

Hi, @sjlombardo It’s doesn’t work, maybe password encypted or wrong

---

<div class="post-metadata">

**Author:** ![FrozenPyrozen](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/frozenpyrozen/32/2296_2.png) [@FrozenPyrozen](https://discuss.zetetic.net/u/FrozenPyrozen)\
**Post date:** [December 6, 2024, 2:37pm UTC](https://discuss.zetetic.net/t/upgrading-from-android-database-sqlcipher-to-sqlcipher-android/6741/46 "2024-12-06T14:37:16Z")

</div>

Hi @developernotes, could you verify that db file needs to be in format `NameDB` without any type extension like `NameDB.sql`?

---

<div class="post-metadata">

**Author:** ![sjlombardo](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/sjlombardo/32/3_2.png) [@sjlombardo](https://discuss.zetetic.net/u/sjlombardo)\
**Post date:** [December 6, 2024, 9:41pm UTC](https://discuss.zetetic.net/t/upgrading-from-android-database-sqlcipher-to-sqlcipher-android/6741/47 "2024-12-06T21:41:30Z")

</div>

@FrozenPyrozen there are no restrictions on database file names. They can have extensions or not, SQLCipher does not care.

You need to remove all this from your `postKey`:

```auto
database.execSQL("PRAGMA kdf_iter = 256000;");
database.execSQL("PRAGMA cipher_hmac_algorithm = HMAC_SHA512;");
database.execSQL("PRAGMA cipher_kdf_algorithm = PBKDF2_HMAC_SHA512;");
database.execSQL("PRAGMA cipher_page_size = 4096;");

```

Those setting are overriding the backwards compatibility settings you made previously with `database.execSQL("PRAGMA cipher_compatibility = 3;");`.

[Previous page](https://discuss.zetetic.net/t/upgrading-from-android-database-sqlcipher-to-sqlcipher-android/6741.md?page=2)
