Skip to content

Encrypt an existing database #1715

Answered by simolus3
Raluca1 asked this question in Q&A
Feb 26, 2022 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

This helpful article was linked on the SQLCipher docs: https://discuss.zetetic.net/t/how-to-encrypt-a-plaintext-sqlite-database-to-use-sqlcipher-and-avoid-file-is-encrypted-or-is-not-a-database-errors/868

Basically, what you need to do is:

  • Open the original database
  • Use the sqlcipher_export function to write the plain-text database into an encrypted file
  • Then open the new file as a NativeDatabase with the key pragma.

If you want to rename the file in the process (e.g. use original.db for the existing plain-text db and original.db.enc for the new one), you can just check if the original.db file exists, perform the conversion in that case and finally delete it. You can put this logic in t…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Raluca1
Comment options

Answer selected by Raluca1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants