--- title: Window.crypto slug: Web/API/Window/crypto translation_of: Web/API/Window/crypto ---
Window.crypto只读属性返回与全局对象关联的 {{domxref("Crypto")}}对象。 此对象允许网页访问某些加密相关服务。
var cryptoObj = window.crypto || window.msCrypto; // for IE 11
genRandomNumbers = function getRandomNumbers() { var array = new Uint32Array(10); window.crypto.getRandomValues(array); var randText = document.getElementById("myRandText"); randText.innerHTML = "The random numbers are: " for (var i = 0; i < array.length; i++) { randText.innerHTML += array[i] + " "; } }
<p id="myRandText">随机数字: </p> <button type="button" onClick='genRandomNumbers()'>生成10个随机数字</button>
{{ EmbedLiveSample('Example') }}
规范 | 状态 | 批注 |
---|---|---|
{{SpecName("Web Crypto API", "#dfn-GlobalCrypto", "Window.crypto")}} | {{Spec2("Web Crypto API")}} | Initial definition |
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Edge | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | 44 {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | 11 {{property_prefix("ms")}} | 20 | 19 | {{CompatVersionUnknown}} |
Feature | Chrome for Android | Firefox Mobile | Firefox OS | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |