Window.crypto只读属性返回与全局对象关联的 Crypto对象。 此对象允许网页访问某些加密相关服务。

语法

var cryptoObj = window.crypto || window.msCrypto; // for IE 11

范例

使用 Window.crypto 来访问getRandomValues() 方法.

JavaScript

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] + " ";
  }
}

HTML

<p id="myRandText">随机数字: </p>
<button type="button" onClick='genRandomNumbers()'>生成10个随机数字</button>

结果

规范

规范 状态 批注
Web Cryptography API
Window.crypto
Recommendation Initial definition

浏览器支持

Feature Chrome Firefox (Gecko) Internet Explorer Edge Opera Safari
Basic support 44 (Yes) (Yes) 11 ms 20 19 (Yes)
Feature Chrome for Android Firefox Mobile Firefox OS IE Phone Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)

另见

文档标签和贡献者

 此页面的贡献者: koaqiu, Taoja
 最后编辑者: koaqiu,