How to decrypt an encrypted sqlcipher database file on command line?

前端 未结 4 1959
北恋
北恋 2020-12-07 18:04

The question is simple

What I have is:

  • I have a database file which is encrypted using sqlcipher.
  • I also
4条回答
  •  生来不讨喜
    2020-12-07 18:33

    This shell script will decrypt a SQLCipher database called mydb.db and create one called mydb-decrypt.db. Params are $1=key, $2, path to read & write from.

    #!/bin/bash
    echo "Decrypting $2 using key $1"
    echo "PRAGMA key='$1';select count(*) from sqlite_master;ATTACH DATABASE '$2/mydb-decrypt.db' AS plaintext KEY '';SELECT sqlcipher_export('plaintext');DETACH DATABASE plaintext;" | sqlcipher $2/mydb.db
    echo "Done."
    

    If you wanted to do this in a single command line, the guts of this are:

    echo "PRAGMA key='$1';select count(*) from sqlite_master;ATTACH DATABASE '$2/mydb-decrypt.db' AS plaintext KEY '';SELECT sqlcipher_export('plaintext');DETACH DATABASE plaintext;" | sqlcipher $2/mydb.db
    

提交回复
热议问题