Xbasic

aes_gcm_decrypt Function

IN THIS PAGE

Syntax

c aes_gcm_decrypt(c ciphertext, c key[, c nonce])

Arguments

ciphertext

Colon-separated base64 string returned by `aes_gcm_encrypt` in the form `ciphertext:tag`.

key

Symmetric key used to encrypt the original plaintext.

nonce

Nonce used during encryption. Required to successfully decrypt when encryption used an explicit or random nonce.

Returns

result

Decrypted plaintext when authentication succeeds; otherwise an empty string.

Description

Decrypt ciphertext using AES-GCM with the given key and nonce.

Examples

Decrypt with missing nonce (fails)
txt = aes_gcm_encrypt("Keep it a secret","Shhh!")
? aes_gcm_decrypt(txt,"Shhh!")
= ""
If the wrong key or nonce is supplied, or if the ciphertext is tampered with, decryption will fail and return an empty string.

Notes

  • The nonce is not embedded in the ciphertext.
  • Store the nonce alongside the ciphertext to enable decryption.