小编Mr.*_*kle的帖子

在 Android 中使用 SQLCipher 加密现有数据库

我的资产中有一个数据库文件,我将其复制到应用程序数据库文件夹中。复制后(它有效),我想用 SQLCipher 加密复制的数据库。

出于某种原因,我收到此错误:

Database: sqlite returned: error code = 26, msg = statement aborts at 5: [ATTACH DATABASE '/data/user/0/com.grandeguru.lagmeup/databases/AIRPORTS_DB.db' AS encrypted KEY 'password';] file is encrypted or is not a database

如果我用根资源管理器查看数据库,它仍然没有加密和可见,所以我认为错误与 encrypt 方法中的文件逻辑有关。

这是我创建的 DatabaseHelper 类的代码,它也管理来自资产的副本:

public class DatabaseHelper extends SQLiteOpenHelper {

private SQLiteDatabase myDB;
private Context context;
public static String DB_NAME = "AIRPORTS_DB.db";
public static String DB_PATH = "/data/data/com.grandeguru.lagmeup/databases/";
public static final int DB_VERSION = 1;


public DatabaseHelper(Context context) {
    super(context, DB_NAME, null, DB_VERSION);
    myDB.loadLibs(context);
    this.context = …
Run Code Online (Sandbox Code Playgroud)

database encryption android android-file sqlcipher

6
推荐指数
1
解决办法
2888
查看次数

标签 统计

android ×1

android-file ×1

database ×1

encryption ×1

sqlcipher ×1