how to encrypt an database using sql cipher

2019-03-22 10:35发布

I want to encrypt an database using sqlcipher.

I have done with the integration os openssl and sqlcipher integration and the build works perfect.

But my issue is I am not able to encrypt my database. I don't know how to perform that activity or method to encrypt a database using sql cipher.

I read on the SQL Cipher but I am not able to understand the same process. I tried the code that is provided by them but not working .

EDIT: Can any one tell my how to set PRAGMA key for the same and then how to start with the encryption ? As only this part is remain for my encryption to get completed.

Please help me out from this situation.

Thanks in advance

1条回答
Luminary・发光体
2楼-- · 2019-03-22 11:23

With SQLCipher make sure you have a brand new SQLite database. Trying to pragma the database with a key while it already has data for some reason just tries to decrypt it.

Here is some additional information on working with an existing SQLite database. In this example encrypted.db is that brand new database you create and pragma.

ATTACH DATABASE 'encrypted.db' AS encrypted KEY 'secret'; -- create a new encrypted database
CREATE TABLE encrypted.t1(a,b); -- recreate the schema in the new database (you can inspect all objects using SELECT * FROM sqlite_master)
INSERT INTO encrypted.t1 SELECT * FROM t1; -- copy data from the existing tables to the new tables in the encrypted database
DETACH DATABASE encrypted;
查看更多
登录 后发表回答