简体   繁体   English

Android : 如果不是硬编码的加密密钥,加密密钥保存在哪里

[英]Android : If not hard-coded encryption key, where to save the encryption key

My android application has account, passwd and other important information needs to store in its database.我的 android 应用程序有帐户、密码和其他重要信息需要存储在其数据库中。 So concern about security, i am now studying encrypt these data to save in the database and decrypt it again when needed.所以担心安全性,我现在正在研究加密这些数据以保存在数据库中并在需要时再次解密。

Using salt and iteration can make the encrypt data more strong.使用盐和迭代可以使加密数据更加强大。 This part i understand how to do it.这部分我明白怎么做。 But my concern here comes that there is a lot discussion that not suggest to hard-coded AES key or PBE key.但我担心的是,有很多讨论不建议硬编码 AES 密钥或 PBE 密钥。 But without the key, i can't decrypt the data again (I do need to decrypt it again).但是没有密钥,我无法再次解密数据(我确实需要再次解密)。

Is there any good suggestion for android application to save the key? android应用程序保存密钥有什么好的建议吗?

Thanks a lot.非常感谢。

It is suggested that the encryption key should be managed using Android Keystore, it is the safest option available at the device end to manage the encryption key.建议使用 Android Keystore 管理加密密钥,这是设备端管理加密密钥最安全的选择。 Android Keystore went through lots of changes from the day it was available for the user applications and that is why I have categorised the recommended approach based on the API level:从 Android Keystore 可用于用户应用程序的那天起,它经历了很多变化,这就是为什么我根据 API 级别对推荐的方法进行分类的原因:

  • API Level < 18: Android does not support Keystore for API level 17 and below. API 级别 < 18: Android 不支持 API 级别 17 及以下的密钥库。 For API level 17 and below, it is recommended that the application use PBKDF2 (Password-Based Key Derivation Functions) securely such that the application should generate the encryption key on runtime while login(using user's password).对于 API 级别 17 及以下,建议应用程序安全地使用 PBKDF2(基于密码的密钥派生函数),以便应用程序在登录时(使用用户密码)在运行时生成加密密钥。 The encryption key should not be stored in the device and should be dynamically generated whenever required using the user's password since there is no secure place in the device to manage the key.加密密钥不应存储在设备中,而应在需要时使用用户密码动态生成,因为设备中没有安全的地方来管理密钥。

    API Level >=18 <23 : Android supports Keystore for API level 18 and above. API 级别 >=18 <23 :Android 支持 API 级别 18 及以上的密钥库。 However, for API level 22 and below the support for AES encryption is not available.但是,对于 API 级别 22 及以下,不支持 AES 加密。 It is recommended that the application generates a random AES key using the default cryptographic provider and encrypt the AES key using RSA public key, generated using Android Keystore through keyPairGenerator.建议应用程序使用默认加密提供程序生成随机 AES 密钥,并使用 RSA 公钥加密 AES 密钥,该密钥是使用 Android Keystore 通过 keyPairGenerator 生成的。 Once the encryption key is encrypted, the same can be stored in the private data storage of the application (For ex: SharedPreferences).一旦加密密钥被加密,它就可以存储在应用程序的私有数据存储中(例如:SharedPreferences)。 When the application starts, the AES key can be decrypted using the RSA private key.当应用程序启动时,可以使用 RSA 私钥解密 AES 密钥。

    API Level >=23: Android supports Keystore with AES support for API level 23 and above. API Level >=23: Android 支持 Keystore 和 API 级别 23 及以上的 AES 支持。 We can directly generate the random AES key using generateKey API and the same is managed automatically by Android Keystore.我们可以使用 generateKey API 直接生成随机 AES 密钥,同样由 Android Keystore 自动管理。

Save your data in .so file.将您的数据保存在 .so 文件中。 you need to implement ndk integration in your project.您需要在您的项目中实现 ndk 集成。 It will make it much more difficult to hack.这将使黑客攻击变得更加困难。 and you can get your value back from c++ file.你可以从 C++ 文件中取回你的价值。 Also check for package name in c++ to make sure your so file is not used in any other application.还要检查 C++ 中的包名称,以确保您的 so 文件未在任何其他应用程序中使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM