Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compatibility of window.crypto.getRandomValues()

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.

like image 269
D.W. Avatar asked Apr 16 '13 02:04

D.W.


People also ask

What is Crypto getRandomValues?

getRandomValues() The Crypto. getRandomValues() method lets you get cryptographically strong random values. The array given as the parameter is filled with random numbers (random in its cryptographic meaning).

What is window Crypto?

The window. crypto property returns a Crypto object which is associated with the global object. This object allows web pages to run various cryptographic operations on the browser side. It has one property, which is the subtle property.


2 Answers

Can I safely assume window.crypto.getRandomValues is present

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
like image 73
bobince Avatar answered Oct 11 '22 10:10

bobince


For a more complete, up-to-date view, it's probably better to just check caniuse.com:

http://caniuse.com/#feat=getrandomvalues

As of December 2015, all modern browsers, except for Opera Mini, support it:

enter image description here

like image 20
laurent Avatar answered Oct 11 '22 10:10

laurent