Window.crypto

  • Revision slug: DOM/window.crypto
  • Revision title: window.crypto
  • Revision id: 54832
  • Created:
  • Creator: evilpie
  • Is current revision? No
  • Comment 20 words added, 74 words removed

Revision Content

{{ domref() }}

{{ SeeCompatTable() }}

The crypto API allows web pages access to certain cryptographic related services. These services are a balance between the functionality web pages need, and the requirement to protect users from malicious web sites.

See JavaScript crypto for details on features implemented only by Mozilla.

Methods

{{ domxref("window.crypto.getRandomValues", "crypto.getRandomValues") }}
This method fills the passed TypedArray with cryptographically random values.

Example

/* assuming that window.crypto.getRandomValues is available */

var array = new Uint32Array(10);
window.crypto.getRandomValues(array);

console.log("Your lucky numbers:");
for (var i = 0; i < array.length; i++) {
    console.log(array[i]);
}

Browser Compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 11.0 {{ webkitbug("22049") }} {{ CompatNo() }} {{ mozbug("440046") }} {{ CompatNo() }} {{ CompatNo() }} 3.1 ?
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{ CompatNo() }} {{ CompatNo() }} {{ mozbug("440046") }} {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }}

Specification

{{ languages( { "ja": "ja/DOM/window.crypto", "pl": "pl/DOM/window.crypto" } ) }}

Revision Source

<p>{{ domref() }}</p>
<p>{{ SeeCompatTable() }}</p>
<p>The crypto API allows web pages access to certain cryptographic related services. These services are a balance between the functionality web pages need, and the requirement to protect users from malicious web sites.</p>
<p>See <a href="/en/JavaScript_crypto" title="en/JavaScript_crypto">JavaScript crypto</a> for details on features implemented only by Mozilla.</p>
<h2>Methods</h2>
<dl> <dt>{{ domxref("window.crypto.getRandomValues", "crypto.getRandomValues") }}</dt> <dd>This method fills the passed TypedArray with cryptographically random values.</dd>
</dl><h2>Example</h2>
<pre class="brush: js">/* assuming that window.crypto.getRandomValues is available */

var array = new Uint32Array(10);
window.crypto.getRandomValues(array);

console.log("Your lucky numbers:");
for (var i = 0; i &lt; array.length; i++) {
    console.log(array[i]);
}</pre>
<h2>Browser Compatibility</h2>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Chrome</th> <th>Firefox (Gecko)</th> <th>Internet Explorer</th> <th>Opera</th> <th>Safari</th> </tr> <tr> <td>Basic support</td> <td>11.0 {{ webkitbug("22049") }}</td> <td>{{ CompatNo() }} {{ mozbug("440046") }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> <td>3.1 ?</td> </tr> </tbody> </table>
</div>
<div id="compat-mobile"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Android</th> <th>Firefox Mobile (Gecko)</th> <th>IE Mobile</th> <th>Opera Mobile</th> <th>Safari Mobile</th> </tr> <tr> <td>Basic support</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }} {{ mozbug("440046") }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> </tr> </tbody> </table>
</div>
<h2 name="Specification">Specification</h2>
<ul> <li><a class="external" href="http://wiki.whatwg.org/wiki/Crypto" title="http://wiki.whatwg.org/wiki/Crypto">WHATWG window.crypto proposal</a></li>
</ul>
<p>{{ languages( { "ja": "ja/DOM/window.crypto", "pl": "pl/DOM/window.crypto" } ) }}</p>
Revert to this revision