在将我的数据库放入资产文件夹之前加密我的数据库以将其与 SQLCipher 一起使用?

Encrypt my DB before putting it in the asset folder to use it with SQLCipher?

我的应用程序可以使用已提供的数据库。我用 sqlite 脚本手动生成了这个,并将其放在我的 android 工作室项目的资产文件夹中。

我想使用 SQLCipher 对其进行加密和处理。我已经在我的 android 应用程序上实现了它,但是我需要在将我的数据库放入资产文件夹之前对其进行加密,以便为用户提供我可以使用 SQLCipher 使用的已经加密的数据库。

我该怎么做?提前致谢。

您可以使用 SQLCipher 命令行创建一个加密的 SQLCipher 数据库 shell:

./sqlcipher foo.db
sqlcipher> PRAGMA key = 'foo';
sqlcipher> CREATE TABLE t1(a,b);
sqlcipher> INSERT INTO t1(a,b) VALUES('one for the money', 'two for the show');
sqlcipher> .q

您可以找到有关创建 SQLCipher shell here. Alternatively, if you already have the database, you can use the sqlcipher_export(...) 便利函数以将纯文本数据库导出到 SQLCipher 加密文件的文档。您可以通过 SQLCipher 命令行 shell 或在 Android 设备上使用 SQLCipher for Android.

以编程方式 运行 sqlcipher_export 函数