9

My app needs to encrypt some data (a user session token). Most examples I see around have a method that generates a Key using a passphrase and a salt, like:

public static Key generateKey(char[] passphrase, byte[] salt) {
    ...
}

My understanding is that we have three options for generating the passphrase:

  1. Have the user enter it every time the app starts (annoying to the user).
  2. Hard-code the passphrase into the app itself. More convenient for the user, but someone can find out what your passphrase is given your app binary.
  3. Randomly generate a passphrase, but then we have to store the generated Key on disk. Now we've just shifted the problem to having to store the key securely on disk, which also seems impossible. If the attacker finds the generated key, big problem.

Option #1 won't work for me. Options #2 and #3 seem inherently flawed, unless I'm grossly misunderstanding how to go about this (hoping that I am). What's the recommended way to do this if we can't go with #1? Do we put in a bunch of obfuscated hoops for an attacker to jump through and hope for the best?

Thanks

4

2 回答 2

2

“我们是否设置了一堆模糊的箍让攻击者跳过并希望得到最好的结果?” 基本上是的。箍的大小和数量取决于您想要制作的难度。

如果你不使用服务器,那么无论你做什么来混淆和加密你的数据都是可逆的。但是,你可以让它变得非常困难。例如,我用来保护某些视频资产的技术。

  1. 将标头的前 1024 个字节(它是 MP4)替换为取自其中一个应用图像资产中间的 1024 个字节。我尝试了几个修复程序,但都无法自动恢复文件 - 尽管可以手动完成。然后...

  2. 使用取自另一个图像资产的 256 字节的私钥加密文件。

  3. 当密钥被提取出来时,它会通过一种算法进行散列,该算法会执行各种无意义的数学运算来破坏密钥。

  4. 使用了预编译混淆器。

我已经尝试自己对此进行逆向工程,即使知道它是如何完成的,而且很难使努力不值得结果。

关于 SO 的讨论很多,总结如下:如果你只是想停止复制,那就让它变得困难(成本与回报),否则就睡得安稳,因为最终你无能为力。如果数据是商业敏感数据,则需要一个与系统级安全相结合的服务器(例如,整个设备加密和无根)。

于 2012-09-27T15:40:06.293 回答
0

您将盐与加密数据一起存储,它不是秘密信息。您可以根据用户输入的内容或某种设备属性获取密钥:(散列)IMEI、MAC 地址等。

基本上,想想你是谁保护你的数据,为什么。由于用户需要这个,因此试图保护它免受他们的侵害没有多大意义。如果您将其存储在私人文件中,其他应用程序无法在非 root 手机上读取它。如果你想在有根手机上保护它,加密可能会有所帮助,但只要密钥存在于应用程序中,或者是基于设备上的某些东西派生的,它只会让它变得更难,而不是不可能恢复。

Android 确实有一个系统范围的密钥库服务,但它没有公共 API,并且可能会发生变化。如果您愿意冒您的应用程序在未来版本上中断的风险,您可以使用它来保护您的密钥。这里有一些细节:http: //nelenkov.blogspot.com/2012/05/storing-application-secrets-in-androids.html

于 2012-09-28T04:18:34.550 回答