Nodes/ComfyUI ARG Toolkit/AES-based Authenticated Encryption
ComfyUI Node

AES-based Authenticated Encryption

Five AES Modes in One Node, and the Nonce Trap That Will Bite You

By AzelusLightvale·Created 12 months ago·Updated about 10 hours ago· 1
AES-based Authenticated Encryption
  • text
  • key
  • nonce
  • associated_data
  • encrypted_txt
modetrue
aes_type
ccm_tag_length16

If you want to hide a message in a ComfyUI workflow and be genuinely certain nobody's reading it, AESAuthenticated is the node. This is the "modern crypto" half of the ARG Toolkit, and instead of one cipher it bundles five authenticated-encryption modes behind a single dropdown: AES-GCM, AES-GCM-SIV, AES-OCB3, AES-SIV, and AES-CCM. Authenticated here is the key word - each of these modes doesn't just encrypt, it also produces a tag that proves the message wasn't tampered with. Decryption fails loudly (well, with a Python exception) if anything was modified. That's a real property, not marketing: plain AES-CBC from a tutorial has no such guarantee, and a changed ciphertext decrypts to garbage you might mistake for a real message.

The node is a wrapper around the cryptography library's AEAD primitives. You feed it a key, a nonce, optional associated data, and the plaintext; it returns a base64 string. Decrypt mode takes that base64 string back and hands you the original text. All five modes share one interface precisely because the math is interchangeable from the node's point of view - that's the kind of consolidation that makes this pack pleasant to use.

The inputs that matter

  • key (BYTESLIKE) - generated by the companion AESAuthenticatedKeygen node, or built with ByteslikeEncode. Do not type one by hand.
  • nonce (BYTESLIKE) - the node's tooltip says it plainly: should be 12 bytes. This is where people get burned.
  • aes_type - the mode dropdown. AES-GCM is the sensible default; AES-SIV and AES-OCB3 are for when nonce-reuse worries keep you up at night.
  • mode - encrypt vs decrypt toggle.
  • associated_data (BYTESLIKE) - authenticated but not encrypted; useful for binding a message to a context (a username, a workflow ID) without hiding it. Leave it empty unless you need it.
  • ccm_tag_length (optional, AES-CCM only) - the tooltip is a rare all-caps warning: DO NOT CHANGE FROM THE DEFAULTS unless you know what you're doing. Drop it to 4 and you're eating a chunk of your security margin for no ARG-shaped reason.

Output is encrypted_txt, a base64 STRING - decrypt mode expects that same base64 text, so it round-trips cleanly through text fields, image metadata, and JSON.

The nonce trap

Reusing a nonce with the same key in GCM or CCM can leak your key's internal state - this is the classic catastrophic AES-GCM failure mode. The toolkit routes around it the right way: wire a SystemRandom node (the pack's os.urandom wrapper, set to 12 bytes) into the nonce input and never, ever fix the value. Where people get burned is being clever: reusing a "convenient" fixed nonce so decrypts are reproducible. Don't. Generate a fresh nonce per encryption and store it alongside the ciphertext - that's standard practice, not paranoia.

AES-SIV and GCM-SIV are explicitly nonce-misuse-resistant; SIV even folds the nonce into its associated data. If you're building something where random nonce generation can't be guaranteed, those two are the honest picks. But for a one-off ARG clue, GCM plus SystemRandom is fine.

Installing it

This node comes with the whole ARG Toolkit pack:

cd ComfyUI/custom_nodes
git clone https://github.com/AzelusLightvale/ComfyUI-ARG-Toolkit

Restart, and it lives under ARG Toolkit → Cryptography → Modern → Authenticated. Manager (search "ComfyUI ARG Toolkit") installs it the same way. The modern crypto nodes depend on cryptography - already in most ComfyUI environments, and pinned in the pack's requirements.txt if you clone manually. No models, no downloads.

Troubleshooting

  • "ValueError: Invalid nonce" on decrypt → the nonce you're feeding decrypt must be byte-identical to the one used to encrypt. The node doesn't store it for you.
  • Decrypt exception about the tag → tampered ciphertext, wrong key, or wrong nonce. All three look the same.
  • Key/nonce won't plug in → they're BYTESLIKE. Run your values through ByteslikeEncode first, or use the keygen/SystemRandom nodes which already emit the right type.

This node is the difference between "looks scrambled" and "actually secret." Use it for the messages you mean, keep the nonce random, and it'll behave.

CategoryARG Toolkit/Cryptography/Modern/Authenticated

Inputs (7)

NameTypeDefaultDescription
textBYTESLIKEInput message here. Has to be in a bytes-like format.
keyBYTESLIKEInput encryption key here. Has to be in a bytes-like format.
nonceBYTESLIKEA random value to use. Should be 12 bytes in size.
associated_dataBYTESLIKEAdditional data that should be authenticated with the key, but does not need to be encrypted. Can be None
modeBOOLEANtrueToggle between encrypting or decrypting a message.
aes_typeCOMBOSwitches between different authenticated encryption form.
ccm_tag_lengthoptINT164–16For AES-CCM specifically, it allows a tag length to be specified. Normally, this defaults to 16, but can be lowered to 4. Unless you know what you're doing, DO NOT CHANGE FROM THE DEFAULTS.

Outputs (1)

NameTypeDescription
encrypted_txtBYTESLIKE