At the moment, my sqlite db file is NOT encrypted and it's copied from the assets
folder to the application data/data/mypackage/databases
folder.
目前,我的sqlite db文件未加密,而是从assets文件夹复制到application data / data / mypackage / databases文件夹。
Now I want to add the SQLCipher libraries to my project and start using them. Can I encrypt the db file and copy it to assets
and use the same key inside the application? Is it possible to encrypt the database on Windows? What I need to do?
现在我想将SQLCipher库添加到我的项目中并开始使用它们。我可以加密db文件并将其复制到资产并在应用程序中使用相同的密钥吗?是否可以在Windows上加密数据库?我需要做什么?
1 个解决方案
#1
-1
i think we should do like that
我想我们应该这样做
SQLiteDatabase normalDB = null;
SQLiteDatabase cryptedDB = null;
normalDB = SQLiteDatabase.openDatabase(dbPath, "", null,
SQLiteDatabase.OPEN_READONLY
| SQLiteDatabase.NO_LOCALIZED_COLLATORS);
cryptedDB = SQLiteDatabase.openOrCreateDatabase(
encrypteddbPath, Constants.CRYPT_KEY, null);
Cursor cursor;
cursor = normalDB.query(TABLE_CITY,
new String[] { FIELD_CITY_CODE, FIELD_NAME1,
FIELD_NAME2, FIELD_NAME3 }, null, null, null,
null, null);
int i = cursor.getCount();
while (i > 0) {
ContentValues newLabelValues = new ContentValues();
newLabelValues.put(FIELD_CITY_CODE, cursor.getString(0));
newLabelValues.put(FIELD_NAME1, cursor.getString(1));
newLabelValues.put(FIELD_NAME2, cursor.getString(2));
newLabelValues.put(FIELD_NAME3, cursor.getString(3));
cryptedDB.insert(TABLE_CITY, null, newLabelValues);
cursor.moveToNext();
}
#1
-1
i think we should do like that
我想我们应该这样做
SQLiteDatabase normalDB = null;
SQLiteDatabase cryptedDB = null;
normalDB = SQLiteDatabase.openDatabase(dbPath, "", null,
SQLiteDatabase.OPEN_READONLY
| SQLiteDatabase.NO_LOCALIZED_COLLATORS);
cryptedDB = SQLiteDatabase.openOrCreateDatabase(
encrypteddbPath, Constants.CRYPT_KEY, null);
Cursor cursor;
cursor = normalDB.query(TABLE_CITY,
new String[] { FIELD_CITY_CODE, FIELD_NAME1,
FIELD_NAME2, FIELD_NAME3 }, null, null, null,
null, null);
int i = cursor.getCount();
while (i > 0) {
ContentValues newLabelValues = new ContentValues();
newLabelValues.put(FIELD_CITY_CODE, cursor.getString(0));
newLabelValues.put(FIELD_NAME1, cursor.getString(1));
newLabelValues.put(FIELD_NAME2, cursor.getString(2));
newLabelValues.put(FIELD_NAME3, cursor.getString(3));
cryptedDB.insert(TABLE_CITY, null, newLabelValues);
cursor.moveToNext();
}