how to encrypt an database using sql cipher

元气小坏坏 提交于 2019-12-09 07:11:27

问题


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:


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;


来源:https://stackoverflow.com/questions/5648698/how-to-encrypt-an-database-using-sql-cipher

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