问题描述
我在我的android程序和java程序中都使用sha1prng作为伪随机数生成器算法.我给它们两个都植入了相同的值.
但是,在android中生成的顺序不同于在Java中生成的顺序.为什么会发生这种情况?该问题的解决方案是什么?
I have used sha1prng in both my android program and java program as the pseudo ramdom number generator algorithm. I seeded both of them with the same value.
But the sequesnce generated in android is different from the one generated in java. Why is this happening and what is the solution to this problem?
推荐答案
我认为这是因为Windows和Android上的SHA1PRNG实现不同.Android使用Crypto作为提供程序,而Windows SDK使用Sun JCE提供程序作为SHA1PRNG实现.即使在此处讨论的JDK版本不同,具有相同种子的输出序列也有所不同: http://www.derkeiler.com/Newsgroups/sci.crypt/2006-04/msg00765.html .对于SHA1PRNG的不同实现,您可能需要检查以下链接: http://www.cigital.com/justice-league-blog/2009/08/14/proper-use-of-javas-securerandom/.
I think it's because SHA1PRNG implementations on Windows and Android are different. Android uses Crypto as the provider while Windows SDK uses Sun JCE provider as SHA1PRNG implementation. The output sequence with the same seed differes even in different versions of JDK as it's discussed here: http://www.derkeiler.com/Newsgroups/sci.crypt/2006-04/msg00765.html. For different implementations of SHA1PRNG you may want to check this link: http://www.cigital.com/justice-league-blog/2009/08/14/proper-use-of-javas-securerandom/.
这篇关于在Android和Windows中使用sha1prng给出不同的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!