Math.random()加密安全吗? [英] Is Math.random() cryptographically secure?
问题描述
在不同的浏览器中,在JavaScript Math.random()
中使用的算法有多好?是否可以使用它生成盐和一次性密码?
How good are algorithms used in Javascript Math.random()
in different browsers? Is it okay to use it for generating salts and one-time passwords?
一个随机
可以使用?
推荐答案
JavaScript的 Math.random()
函数不是加密安全的随机数生成器。您最好使用 JavaScript加密库的Fortuna实施,这是一个强的伪随机数生成器(有请查看 src / js / Clipperz / Crypto / PRNG.js
)或 getRandomValues
的Web Crypto API
Nope; JavaScript's Math.random()
function is not a cryptographically-secure random number generator. You are better off using the JavaScript Crypto Library's Fortuna implementation which is a strong pseudo-random number generator (have a look at src/js/Clipperz/Crypto/PRNG.js
), or the Web Crypto API for getRandomValues
- 以下是详细说明:如何可信赖
- 以下是如何生成一个好的加密等级随机数:在JavaScript中保护随机数字?
- Here is a detailed explanation: How trustworthy is javascript's random implementation in various browsers?
- Here is how to generate a good crypto grade random number: Secure random numbers in javascript?
这篇关于Math.random()加密安全吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!