Create key (generate a key for encrypting the file(s))

The below code is implemented from here, where we create a CryptoKey:

 const key = await window.crypto.subtle.generateKey(
     {
       name: "AES-GCM",
       length: 256,
     },
     true,
     ["encrypt", "decrypt"]
   );

The appearance of the key in the application is extracted by the function:

const readKey = await window.crypto.subtle.exportKey("jwk", key);
console.log(readKey.k);

This key will be used for encryption and decryption.

Last updated