Question

As all you know, we can use sqlcipher to encrypt database and I use it in an android project. For some reason, I dont want to .use it anymore.

by using sqlcipher_export to convert the database.

So my problems are

  1. is there is a good way to let me check is the db encrypted or not and hence decide whether need to have decryption.

2, If there is something unexpected happen (shutdown during migration), what can I do?

Was it helpful?

Solution

Inspect the first 16 bytes of the database file directly, if they are equal to the string "SQLite format 3\000" then the file is not encrypted, and is a standard SQLite database.

If something happens and a crash occurs during sqlcipher_export, the original database will be left untouched. Just run the export again on a subsequent launch.

OTHER TIPS

putting @StephenLombardos string "SQLite format 3\000" into a UTF-8 byte counter comes back as 19 bytes

therefore while his answer is correct it needs a little modification.

I would read the first 17 bytes and check whether they equal "SQLite format 3\0"

If the above statement is true then your db file is Unencrypted

If the statement is false then your db file is Encrypted

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top