Crypto interface represents basic cryptography features available in the current context. It allows access to a cryptographically strong random number generator and to cryptographic primitives.

注意: 此特征可用于 Web 工作者 .

Web 加密 API is accessed through the Window.crypto property, which is a Crypto 对象。

特性

This interface implements properties defined on RandomSource .

Crypto.subtle 只读 安全上下文
返回 SubtleCrypto object providing access to common cryptographic primitives, like hashing, signing, encryption, or decryption.

方法

This interface implements methods defined on RandomSource .

Crypto.getRandomValues()
Fills the passed TypedArray with cryptographically sound random values.

用法注意事项

You should avoid using the Web Crypto API on insecure contexts, even though the Crypto interface is present on insecure contexts, as is the Window.crypto property. In addition, the Crypto 方法 getRandomValues() is available on insecure contexts, but the subtle property is not.

In general, you probably should just treat Crypto as available only on secure contexts.

规范

规范 状态 注释
Web Cryptography API
The definition of 'Crypto' in that specification.
推荐 初始定义

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
Crypto Chrome 11 Edge 12 Firefox 26 IE 11 Opera 15 Safari 6.1 WebView Android Yes Chrome Android 18 Firefox Android 26 Opera Android 14 Safari iOS 6.1 Samsung Internet Android 1.0
getRandomValues() Chrome 11 Edge 12 Firefox 26 IE 11 Opera 15 Safari 6.1 WebView Android ≤37 Chrome Android 18 Firefox Android 26 Opera Android 14 Safari iOS 6.1 Samsung Internet Android 1.0
subtle Chrome 37 Edge 12 Firefox 34 IE 部分支持 11 Opera 24 Safari 10.1
10.1
7 Prefixed
Prefixed Implemented with the vendor prefix: webkit
WebView Android 37 Chrome Android 37 Firefox Android 34 Opera Android 24 Safari iOS 10.3
10.3
7 Prefixed
Prefixed Implemented with the vendor prefix: webkit
Samsung Internet Android 3.0

图例

完整支持

完整支持

部分支持

部分支持

实验。期望将来行为有所改变。

实验。期望将来行为有所改变。

用户必须明确启用此特征。

用户必须明确启用此特征。

要求使用供应商前缀或不同名称。

要求使用供应商前缀或不同名称。

另请参阅

元数据

  • 最后修改: