how to encrypt an database using sql cipher

前端 未结 1 2077
一向
一向 2021-02-11 05:10

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

1条回答
  •  走了就别回头了
    2021-02-11 05:39

    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 or here. 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;
    

    0 讨论(0)
提交回复
热议问题