安全上下文
此特征只可用于
安全上下文
(HTTPS),在某些或所有
支持浏览器
.
decrypt()
方法在
SubtleCrypto
interface decrypts some encrypted data. It takes as arguments a
key
to decrypt with, some optional extra parameters, and the data to decrypt (also known as "ciphertext"). It returns a
Promise
which will be fulfilled with the decrypted data (also known as "plaintext").
const result = crypto.subtle.decrypt(algorithm, key, data);
algorithm
is an object specifying the
algorithm
to be used, and any extra parameters as required. The values given for the extra parameters must match those passed into the corresponding
encrypt()
调用。
RsaOaepParams
对象。
AesCtrParams
对象。
AesCbcParams
对象。
AesGcmParams
对象。
key
是
CryptoKey
containing the key to be used for decryption. If using RSA-OAEP, this is the
privateKey
特性为
CryptoKeyPair
对象。
data
是
BufferSource
containing the data to be decrypted (also known as
ciphertext
).
result
是
Promise
that fulfills with an
ArrayBuffer
containing the plaintext.
The promise is rejected when the following exceptions are encountered:
Raised when the operation failed for an operation-specific reason (e.g. algorithm parameters of invalid sizes, or there was an error decrypting the ciphertext).
decrypt()
method supports the same algorithms as the
encrypt()
方法。
注意 : You can try the working examples on GitHub.
This code decrypts
ciphertext
using RSA-OAEP.
See the complete code on GitHub.
function decryptMessage(privateKey, ciphertext) {
return window.crypto.subtle.decrypt(
{
name: "RSA-OAEP"
},
privateKey,
ciphertext
);
}
This code decrypts
ciphertext
using AES in CTR mode. Note that
counter
must match the value that was used for encryption.
See the complete code on GitHub.
function decryptMessage(key, ciphertext) {
return window.crypto.subtle.decrypt(
{
name: "AES-CTR",
counter,
length: 64
},
key,
ciphertext
);
}
This code decrypts
ciphertext
using AES in CBC mode. Note that
iv
must match the value that was used for encryption.
See the complete code on GitHub.
function decryptMessage(key, ciphertext) {
return window.crypto.subtle.decrypt(
{
name: "AES-CBC",
iv: iv
},
key,
ciphertext
);
}
This code decrypts
ciphertext
using AES in GCM mode. Note that
iv
must match the value that was used for encryption.
See the complete code on GitHub.
function decryptMessage(key, ciphertext) {
return window.crypto.subtle.decrypt(
{
name: "AES-GCM",
iv: iv
},
key,
ciphertext
);
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
Web Cryptography API
The definition of 'SubtleCrypto.decrypt()' in that specification. |
推荐 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
decrypt
|
Chrome 37 |
Edge
部分支持
12
|
Firefox
34
|
IE
部分支持
11
|
Opera 24 | Safari 7 | WebView Android 37 | Chrome Android 37 |
Firefox Android
34
|
Opera Android 24 | Safari iOS 7 | Samsung Internet Android 6.0 |
完整支持
部分支持
见实现注意事项。
用户必须明确启用此特征。
SubtleCrypto.encrypt()
.
SubtleCrypto