Crypto

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

备注: 此特性在 Web Worker 中可用。

Crypto 接口提供了当前上下文中可用的基本的加密功能。它允许访问一个密码学安全的随机数生成器和密码学原语(cryptographic primitive)。

可以在窗口中使用 Window.crypto 属性,或者在 worker 中使用 WorkerGlobalScope.crypto 属性来访问 Crypto

实例属性

该接口实现的属性定义在 RandomSource 中。

Crypto.subtle 只读 安全上下文

返回一个 SubtleCrypto 对象,用来访问公共的密码学原语,例如哈希、签名、加密以及解密。

实例方法

该接口实现的方法定义在 RandomSource 中。

Crypto.getRandomValues()

使用密码学安全的随机数填充传入的 TypedArray

Crypto.randomUUID()

返回一个随机生成的,长度为 36 字符的第四版 UUID。

规范

Specification
Web Cryptography API
# crypto-interface

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
Crypto
getRandomValues()
randomUUID()
subtle
Secure context required

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support
See implementation notes.
Requires a vendor prefix or different name for use.
Has more compatibility info.

参见