本文介绍了window.crypto.getRandomValues()的兼容性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Javascript中生成密码安全的伪随机数。我知道 window.crypto.getRandomValues API,这正是我想要的。但是,我也知道它是相对最近推出的(在2011年左右)。



我可以安全地假设 window.crypto.getRandomValues 是否存在,或者将使用它在一些浏览器上引入兼容性问题?是否有任何主要(广泛使用)的浏览器不支持 window.crypto.getRandomValues (包括手机或桌面浏览器),如果是这样,我需要担心关于?我很高兴获悉有足够的支持,我不再需要担心,如果

解决方案

与往常一样,这取决于您的目标市场,并会随时间而变化。 列出了哪些浏览器支持并计算浏览器市场份额。



这里是一个摘要:




  • IE 11:w /前缀

  • IE Mobile 11:w /前缀


  • Firefox:21 +


  • Firefox Mobile:21 +


  • Safari:从6.1开始

  • b
  • Android浏览器:4.4


  • Opera:15 +


  • :36 +

  • Opera Mini:no


I need to generate cryptographically secure pseudorandom numbers, in Javascript. I know about the window.crypto.getRandomValues API, which does exactly what I want. However, I also know it was introduced relatively recently (in 2011 or so).

Can I safely assume window.crypto.getRandomValues is present, or will using it introduce compatibility problems on some browsers? Are there any major (widely used) browsers which do not support window.crypto.getRandomValues (including mobile or desktop browsers), and if so, which ones do I need to worry about? I would be delighted to learn that there is enough support that I no longer need to worry about fallback methods, if that is indeed the case.

解决方案

As always it depends on your target market and will change over time. caniuse.com lists which browsers support it and calculates the browser marketshare.

Here is a summary:

  • IE 11: w/ prefix
  • IE Mobile 11: w/ prefix

  • Firefox: 21+

  • Firefox Mobile: 21+

  • Safari: from 6.1

  • Safari Mobile: 7.1

  • Chrome: 11+

  • Chrome for Mobile: 23+
  • Android browser: 4.4

  • Opera: 15+

  • Opera Mobile: 36+
  • Opera Mini: no

这篇关于window.crypto.getRandomValues()的兼容性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 10:38