encrypt method
Encrypts buffer's data using the algorithm and key parameters.
Important As of Microsoft Edge, this method returns a Promise object. See Web Cryptography API updates for more info.
![]() |
Syntax
var retVal = SubtleCrypto.encrypt(algorithm, key, buffer);Parameters
- algorithm [in]
-
Type: any
A valid algorithm object.
- key [in]
-
Type: Key
A valid Key object.
- buffer [in, optional]
-
Type: ArrayBufferView
An ArrayBufferView object containing the data to encrypt. If this parameter is specified, the returned operation will immediately complete and return with the encrypted data. Otherwise, the caller is expected to perform the following tasks:
- Provide data through any number of calls to the process method of the CryptoOperation object returned by this (encrypt) method.
- Call the finish method (on this same CryptoOperation object) when done entering data via the process method.
Once the above two steps are completed, the operation will be completed and the encrypted data returned.
Return value
Type: Promise
A Promise object that will encrypt data using the specified algorithm with the supplied key.
Note IE11 returns a CryptoOperation. See Web Cryptography API updates for more info.
Remarks
The encrypt method supports the following cryptographic algorithms:
- AES-CBC
- AES-GCM
- RSAES-PKCS1-v1_5
- RSA-OAEP
See also
Show:
