-1
我試圖使用SQLCipher加密我的數據庫爲我的project.ive添加了所有資產和libs需要使用sqlCipher,但問題是,我有一個專門用於數據庫操作的整個類,所以我有點困惑,要添加所提及的here所需的代碼。我曾嘗試在我的數據庫open()
方法中初始化上述庫,但這只是給了我一個沒有這樣的表異常。如何將SQLcipher添加到android項目?
繼承我的代碼在任何修改之前。任何幫助感激地接受了
public class DataBaseHandler {
public static final String KEY_ID = "id";
public static final String KEY_XCOD = "xcod";
public static final String KEY_YCOD = "ycod";
public static final String KEY_IMG = "img";
public static final String KEY_PATTERN = "pattern";
public static final String KEY_PACKAGENAME = "packagename";
private static final String DATABASE_NAME = "P3UserDb";
private static final String DATABASE_USERTABLE = "LoginDetailsTable";
private static final String DATABASE_PATTERNTABLE = "PatternDetailsTable";
private static final String DATABASE_LOCKEDAPPSTABLE = "LockedAppsTable";
private static final int DATABASE_VERSION = 1;
private DbHelper ourHelper;
private final Context ourContext;
private SQLiteDatabase ourDatabase;
public static class DbHelper extends SQLiteOpenHelper {
public DbHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL("CREATE TABLE " + DATABASE_USERTABLE + " (" + KEY_ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_XCOD
+ " INTEGER NOT NULL, " + KEY_YCOD + " INTEGER NOT NULL, "
+ KEY_IMG + " TEXT NOT NULL);");
db.execSQL("CREATE TABLE " + DATABASE_PATTERNTABLE + " ("
+ KEY_PATTERN + " STRING NOT NULL);");
db.execSQL("CREATE TABLE " + DATABASE_LOCKEDAPPSTABLE + " ("
+ KEY_PACKAGENAME + " STRING);");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXISTS " + DATABASE_USERTABLE);
db.execSQL("DROP TABLE IF EXISTS " + DATABASE_PATTERNTABLE);
db.execSQL("DROP TABLE IF EXISTS " + DATABASE_LOCKEDAPPSTABLE);
onCreate(db);
}
}
public DataBaseHandler(Context c) {
ourContext = c;
}
public DataBaseHandler open() throws SQLException {
ourHelper = new DbHelper(ourContext);
ourDatabase = ourHelper.getWritableDatabase();
return this;
}
public void close() {
ourHelper.close();
}
.
.
.
Other Database operations
.
.
.
}
選中此https://github.com/sqlcipher/android-database-sqlcipher/tree/master/dist/SQLCipherForAndroid-SDK – Gattsu 2014-11-10 14:12:51
爲什麼不按照SQLCypher上的教程。發佈你的「之前」代碼似乎很懶惰。 – Booger 2014-11-10 14:17:11