How to share a webCrypto exported raw key to backend?

965 Views Asked by At

I am generating a symmetric key using web crypto API like this

  let secureToken = await window.crypto.subtle.generateKey(
        {
            name: "AES-CBC",
            length: 256, //can be  128, 192, or 256
        },
        true, //whether the key is extractable (i.e. can be used in exportKey)
        ["encrypt", "decrypt"] //can be "encrypt", "decrypt", "wrapKey", or "unwrapKey"
    )
    const exported = await window.crypto.subtle.exportKey(
      "raw",
      secureToken
    );

 encryptTheKeyAndSend(exported); // How to share?

I want to send this generated key to the backend service (java API which will use this key for decrypt). I am planning to encrypt this key using RSA and send it to the backend service.

Is it possible to share this raw key with the backend service?

Is there any way we can convert this cryptoKey to a byte array or string?

0

There are 0 best solutions below