Math.random()加密安全吗? [英] Is Math.random() cryptographically secure?

查看:1276
本文介绍了Math.random()加密安全吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在不同的浏览器中,在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

  • 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆