Android Sql Database保存加密

时间:2015-03-31 17:49:26

标签: android encryption

我尝试使用加密保存我的sql数据库。我使用sqlcipher加密我的数据库,但是下面的代码不起作用。

在我的活动中:

    try{
            SqlController.DATABASE = Environment.getExternalStorageDirectory() + File.separator + getString(R.string.app_name) + File.separator + SqlController.DATABASE_NAME;
            controller = new SqlController(this);
            controller.getWritableDatabase(SqlController.DATABASE);
        } catch(Throwable e) {

        }

try{
    ArrayList<Map<Boolean, JSONObject>> list = controller.getUsers();
} catch(Throwable e) { }

这是我的SqlController类:

    import info.guardianproject.database.sqlcipher.SQLiteDatabase;
import info.guardianproject.database.sqlcipher.SQLiteOpenHelper;
import info.guardianproject.database.sqlcipher.SQLiteStatement;

public class SqlController extends SQLiteOpenHelper {
    public static String DATABASE_NAME = "database.db";
    public static String DATABASE;

    public SqlController(Context context) {
        super(context, DATABASE, null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase database) {
        String query;
        query = "CREATE TABLE Accs ( Id INTEGER PRIMARY KEY, Name TEXT, Pass TEXT )";
        database.execSQL(query);
    }

    @Override
    public void onUpgrade(SQLiteDatabase database, int version_old, int current_version) {
        String query;
        query = "DROP TABLE IF EXISTS Accs";
        database.execSQL(query);
        onCreate(database);
    }

    public ArrayList<Map<Boolean, JSONObject>> getUsers() {
        ....
    }

}

0 个答案:

没有答案