美文网首页
SQLCipher加解密的操作

SQLCipher加解密的操作

作者: 环零弦 | 来源:发表于2018-02-23 17:01 被阅读0次

    1. 创建加密数据库

    $ sqlcipher encrypted.db
    SQLCipher version 3.8.4.3 2014-04-03 16:53:12
    Enter ".help" for instructions
    Enter SQL statements terminated with a ";"
    sqlite> PRAGMA key = 'thisiskey';
    sqlite> create table encrypted (id integer, name text);
    sqlite> .schema
    CREATE TABLE encrypted (id integer, name text);
    sqlite> .q
    

    2. 打开加密数据库

    $ sqlcipher encrypted.db
    SQLCipher version 3.8.4.3 2014-04-03 16:53:12
    Enter ".help" for instructions
    Enter SQL statements terminated with a ";"
    sqlite> PRAGMA key = 'thisiskey';
    sqlite> .schema
    CREATE TABLE encrypted (id integer, name text);
    

    3. 修改数据库密码

    sqlite> PRAGMA rekey = 'newkey';
    

    4. 加密已有的数据库

    $ sqlcipher banklist.sqlite3 
    SQLCipher version 3.8.4.3 2014-04-03 16:53:12
    Enter ".help" for instructions
    Enter SQL statements terminated with a ";"
    sqlite> ATTACH DATABASE 'encrypted.db' AS encrypted KEY 'thisiskey';
    sqlite> SELECT sqlcipher_export('encrypted');
    sqlite> DETACH DATABASE encrypted;
    

    5. 解密数据库

    $ sqlcipher encrypted.db 
    SQLCipher version 3.8.4.3 2014-04-03 16:53:12
    Enter ".help" for instructions
    Enter SQL statements terminated with a ";"
    sqlite> PRAGMA key = 'thisiskey';
    sqlite> ATTACH DATABASE 'plaintext.db' AS plaintext KEY '';
    sqlite> SELECT sqlcipher_export('plaintext');
    sqlite> DETACH DATABASE plaintext;
    

    参考资料:

    相关文章

      网友评论

          本文标题:SQLCipher加解密的操作

          本文链接:https://www.haomeiwen.com/subject/htbxxftx.html