SQLite.swift icon indicating copy to clipboard operation
SQLite.swift copied to clipboard

How to check if DB is encrypted

Open casperson opened this issue 6 years ago • 3 comments

As shown in this file below, db.rekey() will either change the key or it will encrypt a database with the key if it was not encrypted previously. Is there a way for me to check if the DB is encrypted before I call db.rekey()? I only want to run db.rekey() if the db isn't encrypted, just so it will get encrypted, but then in future cases, I will only want to use db.key() to access database. No need to change the key. It looks like there is an internal function called cipher_key_check() that checks that, any way to expose this somehow to make it an easy check? https://github.com/stephencelis/SQLite.swift/blob/861ff28adec8d175e7f5923340947f0895121416/Sources/SQLite/Extensions/Cipher.swift#L41

casperson avatar Apr 16 '19 21:04 casperson

As another comment, I tested rekey() on an open, unencrypted database, and it didn't encrypt that database? Either I did something wrong, or that is not the correct functionality. In the original documentation for SQLCipher it doesn't do that.

casperson avatar Apr 17 '19 00:04 casperson

For me, I have to call rekey twice for the sql file to get encrypted, is anyone else experiencing this

SolorzanoJose avatar Jun 26 '19 18:06 SolorzanoJose

can you not just try to open it without setting a key?

jberkel avatar Aug 24 '21 18:08 jberkel