如何在Android中的SQLite数据库中存储AES密码?
问题描述:
我想使用此代码在SQLite数据库来存储密码:如何在Android中的SQLite数据库中存储AES密码?
public static String encrypt(String Data) throws Exception {
Key key = generateKey();
Cipher c = Cipher.getInstance(ALGO);
c.init(Cipher.ENCRYPT_MODE, key);
byte[] encVal = c.doFinal(Data.getBytes());
String encryptedValue = new BASE64Encoder().encode(encVal);
return encryptedValue;
}
public static String decrypt(String encryptedData) throws Exception {
Key key = generateKey();
Cipher c = Cipher.getInstance(ALGO);
c.init(Cipher.DECRYPT_MODE, key);
byte[] decordedValue = new BASE64Decoder().decodeBuffer(encryptedData);
byte[] decValue = c.doFinal(decordedValue);
String decryptedValue = new String(decValue);
return decryptedValue;
}
private static Key generateKey() throws Exception {
Key key = new SecretKeySpec(keyValue, ALGO);
return key;
}
这个字节数组作为关键
private static final byte[] keyValue =
new byte[] { 'T', 'h', 'e', 'B', 'e', 's', 't',
'S', 'e', 'c', 'r','e', 't', 'K', 'e', 'y' };
但问题是在哪里存储关键,因为使用关键的,任何人都可以提前对数据进行解密,并导致安全问题..
请帮我....谢谢..
答
使用用户生成的密钥,如引脚屏幕。当应用程序开始向用户请求密钥时,您不需要存储它,然后将其保存在内存中,直到应用程序关闭。
答
无论你在哪里PLAC事e你的秘密钥匙。如果我可以反编译并运行你的代码,那么我只需要在创建密钥后将断点放在一行就可以了。没有任何工作方法可以将加密数据放入代码中,并使其仅供您的代码使用。