Encrypt Data with AES
Encrypt Data with the Advanced Encryption Standard (AES)
Last updated
Was this helpful?
Encrypt Data with the Advanced Encryption Standard (AES)
Last updated
Was this helpful?
The encryptDataWithAES
performs symmetric encryption using the , specifically the Galois/ Counter Mode (GCM). Symmetric encryption is optimal for data encryption and performs the encryption and decryption of data with a single key.
A new AES
key is generated each time the function is called. The data is encrypted using this key and a randomly generated initialized vector (iv
).
The iv
is required for decryption as well, hence it is returned prepended to the encrypted data as a combined Array Buffer
. The encryption key is returned as well, as part of the return object. The key is generated as a CryptoKey object
however it is converted to a base64
encoded string
before being returned.
The function is called as follows:
The following params are available for this function and they must be passed in as an object:
data: ArrayBuffer
: The data to be encrypted passed in as an ArrayBuffer
. The ArrayBuffer
is optimal for data encryption using AES-GCM
and is one of the preferred types for uploading data on Arweave.
The function call returns the following data:
rawEncryptedKeyAsBase64: string
: The encryption key generated at the time of data encryption using AES-GCM
and encoded using Base64
format.
combinedArrayBuffer: ArrayBuffer
: The combination of the random initialized vector prepended to the encrypted data as an ArrayBuffer
.