原项目用的是room,希望实现数据库加密
原来项目用的是room,希望实现数据库加密
是不是按这里的描述, 就好了? 还需要 addMigrations??
SQLiteCipherSpec cipherSpec = new SQLiteCipherSpec() // 指定加密方式,使用默认加密可以省略
.setPageSize(4096)
.setKDFIteration(64000);
WCDBOpenHelperFactory factory = new WCDBOpenHelperFactory() .passphrase("passphrase".getBytes()) // 指定加密DB密钥,非加密DB去掉此行 .cipherSpec(cipherSpec) // 指定加密方式,使用默认加密可以省略 .writeAheadLoggingEnabled(true) // 打开WAL以及读写并发,可以省略让Room决定是否要打开 .asyncCheckpointEnabled(true); // 打开异步Checkpoint优化,不需要可以省略
AppDatabase db = Room.databaseBuilder(this, AppDatabase.class, "app-db") //.allowMainThreadQueries() // 允许主线程执行DB操作,一般不推荐 .openHelperFactory(factory) // 重要:使用WCDB打开Room .build();
As with SQLCipher, migrating from plain-text to encrypted database requires an export operation, which acts like dumping all data from one database and write it to another.
原来项目用的是room,希望实现数据库加密 是不是按这里的描述, 就好了? 还需要 addMigrations??
Neither. You may want to do the exporting in plain SQLiteDatabase, then actually open the encrypted database in the "Room" way after the migration. This may take some time if your database is big. To migrate from plain-text to encrypted database, see sample-encryptdb.