本文介绍了Android 4.3及更早版本的潜在不安全随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新Android SDK后,我在我的代码中发现了这个新警告:

After updating Android SDK, I noticed this new warning in my code:

Android 4.3及更早版本中可能存在不安全的随机数。请阅读https://android-developers.blogspot.com/2013/08/some-securerandom-thoughts.html了解更多信息。

我的使用代码如下: seed 是用户输入的字符串:

My code for usage is following where seed is user typed string:

KeyGenerator kgen = KeyGenerator.getInstance("AES"); // Gives warning
SecureRandom sr = SecureRandom.getInstance("SHA1PRNG", "Crypto");
sr.setSeed(seed);
kgen.init(BLOCKS, sr);
SecretKey skey = kgen.generateKey();

所以我的问题是,由于种子,这个代码仍然可以安全使用吗?如果不是,链接中的代码提供修复以在运行 PRNGFixes.apply()之后使用相同的代码?

So my question is, that is the code still safe to use because of the seed? If not does the code in the link provide fix to use the same code after running PRNGFixes.apply()?

推荐答案

没有。 由于其算法而不安全,因为这些算法产生的密码安全性低于密码序列的数字。种子只能决定你在那个不安全的序列中开始你的PRNG的位置。

No. PRNGs are insecure because of their algorithms, which produce less-than-cryptographically-secure sequences of numbers. The seed only determines where in that insecure sequence you're starting your PRNG.

这篇关于Android 4.3及更早版本的潜在不安全随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 09:32