The SubtleCrypto.encrypt() method returns a Promise of the encrypted data corresponding to the cleartext, algorithm and key given as parameters.
var result = crypto.encrypt(algo, key, cleartext);
algo is an object defining the encryption function to use or a DOMString, the latter being a shorthand for {"name": algo}. Supported values are: {"name": "AES-CBC", iv} where iv is an ArrayBuffer or an ArrayBufferView with 16 random bytes (these should be generated by RandomSource.getRandomValues()).{"name": "AES-CTR", counter, length}{"name": "AES-GCM", iv, additionalData, tagLength} (additionalData and tagLength are optional){"name": "RSA-OAEP", label} (label is optional)key is a CryptoKey containing the key to be used for signing.cleartext is a ArrayBuffer or an ArrayBufferView containing the data to be encrypted, the cleartext.result is a Promise that returns the ciphertext generated by the encryption of the cleartext as an ArrayBuffer.The promise is rejected when the following exception is encountered:
InvalidAccessError when 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.| Specification | Status | Comment |
|---|---|---|
| Web Cryptography API The definition of 'SubtleCrypto.encrypt()' in that specification. | Candidate Recommendation | Initial definition. |
| 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 |
Crypto and Crypto.subtle.SubtleCrypto, the interface it belongs to.
© 2005–2017 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/encrypt