Encrypt Data with AES
Encrypt Data with the Advanced Encryption Standard (AES)
The encryptDatawithAES
performs symmetric encryption using the Advanced Encryption Standard (AES), 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.
Basic Syntax
The function is called as follows:
Input Parameters
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 anArrayBuffer
. TheArrayBuffer
is optimal for data encryption usingAES-GCM
and is one of the preferred types for uploading data on Arweave.
Returned Data
The function call returns the following data:
rawEncryptedKeyAsBase64: string
: The encryption key generated at the time of data encryption usingAES-GCM
and encoded usingBase64
format.combinedArrayBuffer: ArrayBuffer
: The combination of the random initialized vector prepended to the encrypted data as anArrayBuffer
.
Last updated