how to know a sqlite database is encrypted or not

只谈情不闲聊 提交于 2019-12-12 14:46:53

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/17344345/how-to-know-a-sqlite-database-is-encrypted-or-not

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