問題描述
如何在 javascript 中生成加密安全的隨機數(shù)?
How do I generate cryptographically secure random numbers in javascript?
推薦答案
例如,您可以使用鼠標移動作為隨機數(shù)的種子,在 onmousemove 事件發(fā)生時讀出時間和鼠標位置,將該數(shù)據(jù)提供給白化函數(shù)并你手頭會有一些頭等艙.但請確保用戶在使用數(shù)據(jù)之前已充分移動鼠標.
You can for instance use mouse movement as seed for random numbers, read out time and mouse position whenever the onmousemove event happens, feed that data to a whitening function and you will have some first class random at hand. Though do make sure that user has moved the mouse sufficiently before you use the data.
我自己通過制作密碼生成器對這個概念進行了一些嘗試,我不能保證我的美白功能是完美無缺的,但是不斷地重新播種我很確定它對于這項工作來說已經(jīng)足夠了:電子商務.hopto.org/generator.htm
I have myself played a bit with the concept by making a password generator, I wouldn't guarantee that my whitening function is flawless, but being constantly reseeded I'm pretty sure that it's plenty for the job: ebusiness.hopto.org/generator.htm
Edit2:它現(xiàn)在有點適用于智能手機,但只能在收集熵時禁用觸摸功能.Android 將無法以任何其他方式正常工作.
It now sort of works with smartphones, but only by disabling touch functionality while the entropy is gathered. Android won't work properly any other way.
這篇關于在javascript中保護隨機數(shù)?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!