我想知道:
在创建数据库时,我们是否可以在SQLite中使用Context.MODE_PRIVATE来防止不必要的数据库访问。
我在google上没有得到任何例子。
如何在数据库中使用此Context.MODE_PRIVATE。
请帮帮我。提供任何链接或示例。
IN THIS LINK他们谈论的是文件。所以数据库也是文件。
我如何实现这一点?
发布于 2013-03-12 13:48:24
正如通用件所提到的,内部存储上的SQLite数据库默认是私有的。但正如其他人所提到的,根手机总是可以访问你的文件。
相反,您可以使用任何加密算法将数据保存在DB中,这将帮助您限制可读性,除非入侵者知道加密算法。
您不能在SQLite中设置"Context.MODE_PRIVATE“标志。
发布于 2013-03-12 13:55:45
在创建数据库时,以下语法非常有用
openOrCreateDatabase(String path, int mode, SQLiteDatabase.CursorFactory factory)例如,
openOrCreateDatabase("StudentDB",Context.MODE_PRIVATE,null);请参阅我在this网站上的教程。
发布于 2019-07-22 13:22:23
选项1:使用SQLcipher。
选项2:永远不会破解的安全方法。它并不完美,但总比什么都没有好。
1)使用此函数插入数据:
public static String getEncryptedString(String message) {
String cipherText = null;
try {
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(("YOUR-SECURE-PASSWORD-KEY").getBytes(), "AES"));
byte[] bytes = cipher.doFinal(message.getBytes());
cipherText = Base64.encodeToString(bytes, Base64.DEFAULT);
} catch(Exception ex) {
cipherText = "Error in encryption";
Log.e(TAG , ex.getMessage());
ex.printStackTrace();
}
return cipherText;
}2)从数据库中获取数据,传入此函数参数:
//This function returns output string
public static String getDecryptedString(String encoded) {
String decryptString = null;
try {
byte[] bytes = Base64.decode(encoded, Base64.DEFAULT);
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(("YOUR-SECURE-PASSWORD-KEY").getBytes() , "AES"));
decryptString = new String(cipher.doFinal(bytes), "UTF-8");
} catch(Exception ex) {
decryptString = "Error in decryption";
ex.printStackTrace();
}
return decryptString;
}3)这些方法的优点:-没有正确的密钥就不可能解密。- AES加密是一种非常安全的加密方法。
4)将您的AES密钥存储在c++文件中。
https://stackoverflow.com/questions/14848402
复制相似问题