The countdown is on: Register today + save your seatLearn how to leverage new AI features and observability tools, attend technical deep dives. & leave with tips for growing your observability strategy. Seats are limited and in high demand, register now!
📢 Registration + agenda now live
Explore the latest Grafana Cloud and AI solutions, learn tips & tricks from demos and hands-on workshops, and get actionable advice to advance your observability strategy. Register now and get 50% off - limited tickets available (while they last!).
The AesGcmParams object represents the object that should be passed as the algorithm parameter into the
encrypt and
decrypt operation when using the AES-GCM algorithm.
The initialization vector. It must be 12 bytes long, unpredictable and cryptographically random. It must be unique for every encryption operation carried out with a given key. Never reuse an iv with the same key. Yet, it doesn’t need to be secret and can be transmitted along with the ciphertext.
additionalData (optional)
ArrayBuffer, TypedArray or DataView
Additional data that should be authenticated, but not encrypted. It must be included in the calculation of the authentication tag, but not encrypted itself.
tagLength (optional)
number
The length of the authentication tag in bits. Should be set, and will default to 96.
Example
JavaScript
exportdefaultasyncfunction(){const plaintext =stringToArrayBuffer('Hello, World!');/**
* Generate a symmetric key using the AES-CBC algorithm.
*/const key =await crypto.subtle.generateKey({name:'AES-GCM',length:256,},true,['encrypt','decrypt']);/**
* Encrypt the plaintext using the AES-CBC key with
* have generated.
*/const ciphertext =await crypto.subtle.encrypt({name:'AES-GCM',iv: crypto.getRandomValues(newUint8Array(12)),},
key,
plaintext
);}functionstringToArrayBuffer(str){const buf =newArrayBuffer(str.length *2);// 2 bytes for each charconst bufView =newUint16Array(buf);for(let i =0, strLen = str.length; i < strLen; i++){
bufView[i]= str.charCodeAt(i);}return buf;}