Skip to main content

Function.encrypt

function encrypt(key: JsonWebKey, data: string): Promise<EncryptedData>

Encrypts the given data using the provided JsonWebKey.

Size Details:

  • IV (Initialization Vector): 96 bits (12 bytes), standard for AES-GCM.
  • Key: Must match the length specified during generation (here 256 bits).
  • Data: Variable size depending on the data to be encrypted.

Parameters

ParameterTypeDescription
keyJsonWebKeyThe key to use for encryption.
datastringThe data to encrypt.

Returns

Promise<EncryptedData>

A promise that resolves to the encrypted data, including the initialization vector (iv) and the ciphertext.

Throws

Throws an error if encryption fails.