This article needs a technical review. How you can help.
The SubtleCrypto.encrypt() method returns a Promise of the encrypted data corresponding to the cleartext, algorithm and key given as parameters.
Syntax
var result = crypto.encrypt(algo, key, cleartext);
Parameters
algois an object defining the encryption function to use or aDOMString, the latter being a shorthand for{"name": algo}. Supported values are:{"name": "AES-CBC", iv}whereivis anArrayBufferor anArrayBufferViewwith 16 random bytes (these should be generated byRandomSource.getRandomValues()).{"name": "AES-CTR", counter, length}{"name": "AES-GCM", iv, additionalData, tagLength}(additionalDataandtagLengthare optional){"name": "RSA-OAEP", label}(labelis optional)
keyis aCryptoKeycontaining the key to be used for signing.cleartextis aArrayBufferor anArrayBufferViewcontaining the data to be encrypted, the cleartext.
Return value
resultis aPromisethat returns the ciphertext generated by the encryption of the cleartext as anArrayBuffer.
Exceptions
The promise is rejected when the following exception is encountered:
InvalidAccessErrorwhen the encryption key is not a key for the requested encryption algorithm or when trying to use an algorithm that is either unknown or isn't suitable for encryption.
Specifications
| Specification | Status | Comment |
|---|---|---|
| Web Cryptography API The definition of 'SubtleCrypto.encrypt()' in that specification. |
Candidate Recommendation | Initial definition. |
Browser compatibility
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | 37 | 34 (34) | Not supported | ? | Not supported |
| Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | (Yes) | 37 | 34.0 (34) | Not supported | ? | Not supported |
See also
CryptoandCrypto.subtle.SubtleCrypto, the interface it belongs to.