如何在命令行上解密加密的sqlcipher数据库文件?

Vin*_*hwa 16 encryption terminal sqlcipher

问题很简单

我有的是:

  • 我有一个使用sqlcipher 加密数据库文件.
  • 我也用于加密这个db文件的密码

我需要的是:

  • 我需要解密数据库文件 /需要一个未加密/非加密/解密的数据库文件.

Vin*_*hwa 35

下载并构建sqlcipher

- 如果已安装sqlcipher,请执行此操作

https://github.com/sqlcipher/sqlcipher中将代码拉到目录中(比如〜/ sqlcipher)

mkdir ~/bld;        #  Build will occur in a sibling directory
cd ~/bld;           #  Change to the build directory
../sqlcipher/configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="-lcrypto"; 
                    #configure sqlcipher 

make install;       #  Install the build products
Run Code Online (Sandbox Code Playgroud)

将数据库解密为纯文本数据库

$ cd ~/;
$ ./sqlcipher encrypted.db 
sqlite> PRAGMA key = 'testkey'; 
sqlite> ATTACH DATABASE 'plaintext.db' AS plaintext KEY '';  -- empty key will disable encryption
sqlite> SELECT sqlcipher_export('plaintext'); 
sqlite> DETACH DATABASE plaintext; 
Run Code Online (Sandbox Code Playgroud)

在〜/ plaintext.db找到解密的数据库,您可以在任何sqlite浏览器中使用这个数据库.

更新:2015年9月

http://sqlitebrowser.org现在支持sqlcipher数据库.那很整齐.

  • “文件已加密或不是数据库”,我得到了错误。当我附加数据库 (2认同)
  • 顺便说一句,如果您在 macOS 上并使用 Homebrew,则可以使用“brew install sqlcipher”安装“sqlcipher”。 (2认同)

小智 10

此shell脚本将解密名为mydb.db的SQLCipher数据库并创建一个名为mydb-decrypt.db的数据库.参数是$ 1 =密钥,$ 2,读写路径.

#!/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."
Run Code Online (Sandbox Code Playgroud)

如果你想在一个命令行中执行此操作,那么它的内容是:

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
Run Code Online (Sandbox Code Playgroud)


Sam*_*RAK 9

使用 SQLiteStudio

SqliteStudio

选择 SQLiteChiper 并输入密码。数据库将被打开。