The SubtleCrypto.decrypt() method returns a Promise of the plaintext corresponding to the ciphertext data, algorithm and key given as parameters.


var result = crypto.subtle.decrypt(algorithm, key, data);


Return value


The promise is rejected when the following exceptions are encountered:

when the requested operation is not valid for the provided key (e.g. invalid encryption algorithm, or invalid key for specified encryption algorithm).
when the operation failed for an operation-specific reason (e.g. algorithm parameters of invalid sizes, or the result of the decryption is a fail).


const pwUtf8 = new TextEncoder().encode('my password');
const pwHash = await crypto.subtle.digest('SHA-256', pwUtf8);

const alg = { name: 'AES-GCM', iv: iv };
const key = await crypto.subtle.importKey('raw', pwHash, alg, false, ['decrypt']);

const ptBuffer = await crypto.subtle.decrypt(alg, key, ctBuffer);

const plaintext = new TextDecoder().decode(ptBuffer);

The iv is as supplied to SubtleCrypto.encrypt(); the ctBuffer is the ciphertext returned from SubtleCrypto.encrypt().


Specification Status Comment
Web Cryptography API
The definition of 'SubtleCrypto.decrypt()' in that specification.
Recommendation Initial definition.

Browser compatibility

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support 37 (Yes) 34 (34) No support ? No support
Feature Android Chrome for Android Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) 37 (Yes) 34.0 (34) No support ? No support

See also

Document Tags and Contributors

 Contributors to this page: Dans24, since2016c, chrisveness, abbycar, oughter, pstricker, ignisvulpis, teoli
 Last updated by: Dans24,