久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Java中的SecureRandom安全種子

SecureRandom safe seed in Java(Java中的SecureRandom安全種子)
本文介紹了Java中的SecureRandom安全種子的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

這段代碼安全嗎?

 SecureRandom randomizer = new SecureRandom(String.valueOf(new Date().getTime()).getBytes());

這是實(shí)例化安全隨機(jī)種子的正確方法嗎?

Is this the right way to instance the seed of secure random?

推薦答案

不,你應(yīng)該避免使用 SecureRandom(byte[]) 構(gòu)造函數(shù).它既不安全也不便攜.

No, you should avoid the SecureRandom(byte[]) constructor. It is both unsafe and non-portable.

它是不可移植的,因?yàn)樗?Windows 和其他操作系統(tǒng)上的行為不同.

It is non-portable because it behaves differently on Windows vs. other operating systems.

在大多數(shù)操作系統(tǒng)上,默認(rèn)算法是NativePRNG",它從操作系統(tǒng)獲取隨機(jī)數(shù)據(jù)(通常是 "/dev/random")并忽略您提供的種子.

On most OSes, the default algorithm is "NativePRNG", which obtains random data from the OS (usually "/dev/random") and ignores the seed you provide.

在 Windows 上,默認(rèn)算法是SHA1PRNG",它將您的種子與計(jì)數(shù)器結(jié)合起來并計(jì)算結(jié)果的哈希值.

On Windows, the default algorithm is "SHA1PRNG", which combines your seed with a counter and computes a hash of the result.

在您的示例中這是個(gè)壞消息,因?yàn)檩斎?當(dāng)前 UTC 時(shí)間,以毫秒為單位)的可能值范圍相對較小.例如,如果攻擊者知道 RNG 是在過去 48 小時(shí)內(nèi)播種的,他們可以將種子縮小到小于 228 個(gè)可能的值,即您只有 27 位的熵.

This is bad news in your example, because the input (the current UTC time in milliseconds) has a relatively small range of possible values. For example if an attacker knows that the RNG was seeded in the last 48 hours, they can narrow the seed down to less than 228 possible values, i.e. you have only 27 bits of entropy.

另一方面,如果您在 Windows 上使用了默認(rèn)的 SecureRandom() 構(gòu)造函數(shù),它將調(diào)用本機(jī) CryptoGenRandom 函數(shù)來獲取 128 位種子.因此,通過指定您自己的種子,您已經(jīng)削弱了安全性.

If on the other hand you had used the default SecureRandom() constructor on Windows, it would have called the native CryptoGenRandom function to get a 128-bit seed. So by specifying your own seed you have weakened the security.

如果您真的想覆蓋默認(rèn)種子(例如用于單元測試),您還應(yīng)該指定算法.例如

If you really want to override the default seed (e.g. for unit testing) you should also specify the algorithm. E.g.

SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
sr.setSeed("abcdefghijklmnop".getBytes("us-ascii"));

另請參閱如何使用 Java SecureRandom 解決性能問題?
和這篇博文:http://www.cigital.com/justice-league-blog/2009/08/14/proper-use-of-javas-securerandom/

這篇關(guān)于Java中的SecureRandom安全種子的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Java Remove Duplicates from an Array?(Java從數(shù)組中刪除重復(fù)項(xiàng)?)
How to fix Invocation failed Unexpected Response from Server: Unauthorized in Android studio(如何修復(fù)調(diào)用失敗來自服務(wù)器的意外響應(yīng):在 Android 工作室中未經(jīng)授權(quán))
AES encryption, got extra trash characters in decrypted file(AES 加密,解密文件中有多余的垃圾字符)
AES Error: Given final block not properly padded(AES 錯(cuò)誤:給定的最終塊未正確填充)
Detecting incorrect key using AES/GCM in JAVA(在 JAVA 中使用 AES/GCM 檢測不正確的密鑰)
AES-256-CBC in Java(Java 中的 AES-256-CBC)
主站蜘蛛池模板: 国产亚洲网站 | 午夜视频网站 | 日本亚洲一区 | 国产精品视频在线观看 | 日韩字幕 | 精品欧美一区免费观看α√ | av免费观看在线 | 日韩在线播放中文字幕 | 精品欧美一区二区三区久久久 | 欧美一区二 | 一级大片免费 | 成人性生交大片免费看r链接 | 欧美日韩精品中文字幕 | 日韩一区二区福利视频 | 亚洲精品女优 | 日韩精品免费看 | 一区二区在线免费观看视频 | 91久久综合亚洲鲁鲁五月天 | 日韩一二区在线观看 | 久久精品免费 | 在线色网站 | 亚洲欧美日韩在线 | 日本黄色大片免费 | 久久久亚洲一区 | 老牛影视av一区二区在线观看 | 91视频在线看| 亚洲国产aⅴ成人精品无吗 国产精品永久在线观看 | 国产亚洲欧美另类一区二区三区 | 久久精品亚洲精品国产欧美 | 日本超碰 | 国产一区二区高清在线 | 在线视频成人 | 在线观看中文字幕视频 | 国产精品久久久久久av公交车 | 久久久精品网站 | 97伦理影院 | 精久久久| 欧美片网站免费 | 国产精品成人一区二区三区 | 精品国产一区二区三区久久久蜜月 | 免费99精品国产自在在线 |