翻译正在进行中。

Web Crypto API 为脚本提供加密了一套关于密码(学)的接口,以便用于构建需要使用密码的系统。

警告: Web Crypto API 提供了许多底层的密码学原语。它们很容易被误用,并且踩到一些微妙的陷阱。

即使正确地使用了这些基础的密码学函数,密钥管理和整体的安全系统设计也是非常困难的,这些通常都是属于安全专家的领域。

安全系统设计和实现过程中出现的错误可以使得整个系统的安全性不复存在。

如果你不确定你知道自己在做什么,那么你可能不应该使用这些 API。

接口

有些浏览器实现了叫做 Crypto 的接口,但是缺乏良好的定义,或在密码学上是不健全的。为了避免混乱,这个接口的方法和属性已经被实现 Web Crypto API 的浏览器所移除,并且所有的 Web Crypto API 方法都可以在新的接口中使用: SubtleCryptoCrypto.subtle 属性可以获取到一个实现了新接口的对象。

规范

Specification Status Comment
Web Cryptography API Recommendation Initial definition

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Basic supportChrome Full support 11Edge Full support 12Firefox Full support 26IE Full support 11Opera Full support 15Safari Full support 6.1WebView Android Full support YesChrome Android Full support 18Edge Mobile Full support 12Firefox Android Full support 26Opera Android Full support 14Safari iOS Full support 6.1Samsung Internet Android Full support Yes
subtle
Experimental
Chrome Full support 37Edge Full support 12Firefox Full support 34
Full support 34
No support 32 — 34
Disabled
Disabled From version 32 until version 34 (exclusive): this feature is behind the dom.webcrypto.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
IE Partial support 11Opera Full support 24Safari Full support 10.1
Full support 10.1
Full support 7
Prefixed
Prefixed Implemented with the vendor prefix: webkit
WebView Android Full support 37Chrome Android Full support 37Edge Mobile Full support 12Firefox Android Full support 34
Full support 34
No support 32 — 34
Disabled
Disabled From version 32 until version 34 (exclusive): this feature is behind the dom.webcrypto.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
Opera Android Full support 24Safari iOS Full support 10.1
Full support 10.1
Full support 7
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Samsung Internet Android Full support Yes
getRandomValuesChrome Full support 11Edge Full support 12Firefox Full support 26IE Full support 11Opera Full support 15Safari Full support 4WebView Android Full support YesChrome Android Full support 18Edge Mobile Full support 12Firefox Android Full support 26Opera Android Full support 14Safari iOS Full support 4Samsung Internet Android Full support Yes

Legend

Full support  
Full support
Partial support  
Partial support
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
User must explicitly enable this feature.
User must explicitly enable this feature.
Requires a vendor prefix or different name for use.
Requires a vendor prefix or different name for use.

 

文档标签和贡献者

此页面的贡献者: mdnwebdocs-bot, cissoid, LiangXingYong, auver, TooBug
最后编辑者: mdnwebdocs-bot,