Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

Window: crypto property

BaselineWidely available

Thecrypto read-only property of theWindow interface returns theCrypto object for this window's scope. This object gives web pages access to certain cryptographic related services.

Although the property itself is read-only, all of its methods (and the methods of itschild object,SubtleCrypto) are not read-only, and therefore vulnerableto attack bypolyfill.

Althoughcrypto is available on all windows, the returnedCrypto object only has one usable feature in insecure contexts: thegetRandomValues() method. In general, you should use this API only in secure contexts.

Value

An instance of theCrypto interface, providing access to general-purpose cryptography and a strong random-number generator.

Examples

This example uses thecrypto property to access thegetRandomValues() method.

HTML

html
<p>The random numbers are:</p><button type="button">Generate 10 random numbers</button>

JavaScript

js
function genRandomNumbers() {  const array = new Uint32Array(10);  globalThis.crypto.getRandomValues(array);  const randText = document.getElementById("myRandText");  randText.textContent = `The random numbers are: ${array.join(" ")}`;}document.querySelector("button").addEventListener("click", genRandomNumbers);

Result

Specifications

Specification
Web Cryptography Level 2
# dom-windoworworkerglobalscope-crypto

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp