简体   繁体   English

如何安全地在Android中存储密钥?

[英]How to store secretkey in Android securely?

I'm reading about store a secretkey (to encrypt/to decrypt data) and seems there is no way achieve that. 我正在阅读关于存储密钥(加密/解密数据)的内容,似乎没有办法实现这一点。 One can only increase difficult for an attacker accomplish this. 人们只能增加攻击者实现这一目标的难度。

It's really like that? 它真的像那样?

What I've got so far: 到目前为止我得到了什么:

Store in shared preference ( private mode ) - Rooted phone will be able to retrieve it. 存储在共享首选项(私人模式) - Root电话将能够检索它。

NDK C/C++ native code, create .so file - Hard to decompile, but one could call this .so file and retrieve it. NDK C / C ++本机代码,创建.so文件 - 难以反编译,但可以调用此.so文件并检索它。

A webserver to store the key, looks useless, if a have to send credentials, a malicious ware could log key taps. 用于存储密钥的Web服务器看起来毫无用处,如果必须发送凭据,则恶意软件可以记录密钥。

Am I too paranoic? 我太偏执了吗?

Why do not you use Android Keystore?it is designed for this purpose https://developer.android.com/training/articles/keystore.html 为什么不使用Android Keystore?它是为此目的而设计的https://developer.android.com/training/articles/keystore.html

The Android Keystore system lets you store cryptographic keys in a container to make it more difficult to extract from the device Android Keystore系统允许您将加密密钥存储在容器中,从而使从设备中提取更加困难

It has considerable advantages over shared preferences or private files like extraction prevention or key use authorization I do not consider storing private keys on the server 与共享首选项或私有文件(如提取防护或密钥使用授权)相比,它具有相当大的优势。我不考虑在服务器上存储私钥

Security Features 安全功能

Android Keystore system protects key material from unauthorized use. Android Keystore系统可保护密钥材料免遭未经授权的使用。 Firstly, Android Keystore mitigates unauthorized use of key material outside of the Android device by preventing extraction of the key material from application processes and from the Android device as a whole. 首先,Android Keystore通过阻止从应用程序进程和整个Android设备中提取密钥材料 ,减少了对Android设备外部密钥材料的未授权使用。 Secondly, Android KeyStore mitigates unauthorized use of key material on the Android device by making apps specify authorized uses of their keys and then enforcing these restrictions outside of the apps' processes. 其次,Android KeyStore通过使应用指定其密钥的授权使用,然后在应用程序的进程之外强制执行这些限制, 减轻了对Android设备上未授权使用密钥材料的影响。

In some devices with dedicated hardware it is implemented on it. 在一些具有专用硬件的设备中,它在其上实现。 As a programmer you can know is a key is hardware-protected 作为程序员,您可以知道密钥是硬件保护的

The concept is similar to iOS KeyChain, but whereas IOS KeyChain can store passwords, generate and import cryptographic keys, Android KeyStore only allows to generate cryptographic secret keys by the application ( no import functions) 这个概念类似于iOS KeyChain,但是IOS KeyChain可以存储密码,生成和导入加密密钥,Android KeyStore只允许应用程序生成加密密钥(无导入功能)

The keys also can be protected requiring user to unlock the device and / or presenting the fingerprint 还可以保护密钥,要求用户解锁设备和/或呈现指纹

For example, to secure a password, is possible to generate a cipher key protected with fingerprint, and use it to encrypt user's credentials that could be stored in preferences 例如,为了保护密码,可以生成受指纹保护的密码密钥,并使用它来加密可以存储在首选项中的用户凭证

You are correct. 你是对的。 Most security experts will tell you there is no such thing as an absolutely secure system. 大多数安全专家会告诉你,没有一个绝对安全的系统。 The proper way to think of it is in terms of the level of resources an attacker must use to break your system. 考虑它的正确方法是攻击者必须使用的资源级别来破坏您的系统。

You then balance your security measures between the value of the data and other considerations like the complexity of your solution and other costs. 然后,您可以在数据值与其他考虑因素(如解决方案的复杂性和其他成本)之间平衡安全措施。

To elaborate on your examples, assuming you aren't worried about the legitimate owner/user of the phone being the attacker, you can assess as follows: 要详细说明您的示例,假设您不担心手机的合法所有者/用户是攻击者,您可以评估如下:

  1. Rooting a phone is a risk if an attacker gets physical possession. 如果攻击者获得实际拥有权,则生根电话是一种风险。 To assess, how valuable is the data versus the likelihood of a phone getting lost/stolen, the person who then has it caring to get the key and knowing how to root a phone. 要评估数据的价值与手机丢失/被盗的可能性之间的差异,然后让他们关心获取密钥并知道如何根据手机进行操作。
  2. Obscuring secret information is generally considered useless. 隐藏秘密信息通常被认为是无用的。 I personally think it depends a little bit on the circumstances. 我个人认为这取决于具体情况。 Here, again, an attacker would need to root the phone, etc. The problem with obscuring secret information is it only takes one person to figure out what you've done and make that information available to completely lose the value in doing it. 在这里,再一次,攻击者需要根据电话等。隐藏秘密信息的问题是,只需要一个人弄清楚你做了什么,并使这些信息可用,完全失去了做这件事的价值。
  3. If you have a key logger, what security do you have anyway? 如果你有一个键盘记录器,你还有什么安全保障?

You should look at the possibility of using a "secure element". 您应该考虑使用“安全元素”的可能性。 See this post on the security Stack Exchange for some good information. 有关一些好的信息,请参阅安全性Stack Exchange上的这篇文章

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

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