4.9 KiB
Symmetric Encrypt/Decrypt
Encrypts or decrypts data using a variety of standard symmetric ciphers and modes. This node is a wrapper around the cryptography library.
Source library: cryptography
Overview
This is a flexible, general-purpose node for performing symmetric encryption. It allows you to choose from a wide range of algorithms (like AES, ChaCha20) and modes of operation (like CBC, GCM, CTR) to fit different cryptographic needs.
Parameters
- text: The
BYTESLIKEdata to be encrypted or decrypted. - key: The encryption key as a
BYTESLIKEobject. The required size depends on the chosen algorithm. - iv: The initialization vector or nonce as a
BYTESLIKEobject. For XTS mode, this is thetweak. Not used by all algorithms/modes (e.g., ECB, stream ciphers). - algorithm: The symmetric algorithm to use (e.g.,
AES,ChaCha20,TripleDES). - modes: The cipher mode of operation (e.g.,
CBC,GCM,CTR). - algorithm: The symmetric algorithm to use (e.g.,
AES,ChaCha20). Several legacy algorithms likeTripleDESandBlowfishare supported but considered deprecated. - modes: The cipher mode of operation (e.g.,
CBC,GCM,CTR). Legacy modes likeOFBandCFBare supported but considered deprecated. - mode: Toggles between
EncryptandDecrypt. - tag: (Optional) For GCM decryption, this is the
BYTESLIKEauthentication tag that must be provided to verify the ciphertext's integrity and authenticity. - min_tag_length: (Optional) For GCM, the minimum acceptable tag length during decryption.
- nonce: (Optional) A
BYTESLIKEnonce, used specifically forChaCha20in this implementation.
Outputs
- output: The resulting ciphertext (on encryption) or plaintext (on decryption) as a
BYTESLIKEobject. - tag: When using GCM mode for encryption, this output provides the generated authentication tag as a
BYTESLIKEobject. This tag is required for decryption.
Algorithm and Mode Compatibility
The cryptography library will raise an error if an incompatible algorithm and mode are selected. The following table provides a general guide. Items marked with (D) are deprecated according to the cryptography library and should be avoided for any serious projects.
| Algorithm | CBC | CTR | OFB (D) | CFB (D) | CFB8 (D) | GCM | XTS | ECB | None |
|---|---|---|---|---|---|---|---|---|---|
| AES | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ❌ |
| AES128 | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ❌ | ✔ | ❌ |
| AES256 | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ❌ | ✔ | ❌ |
| Camellia (D) | ✔ | ✔ | ✔ | ✔ | ✔ | ❌ | ❌ | ✔ | ❌ |
| ChaCha20 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✔ |
| TripleDES (D) | ✔ | ✔ | ✔ | ✔ | ✔ | ❌ | ❌ | ✔ | ❌ |
| SM4 | ✔ | ✔ | ✔ | ✔ | ❌ | ❌ | ❌ | ✔ | ❌ |
| ARC4 (D) | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✔ |
| Blowfish (D) | ✔ | ✔ | ✔ | ✔ | ❌ | ❌ | ❌ | ✔ | ❌ |
| CAST5 (D) | ✔ | ✔ | ✔ | ✔ | ❌ | ❌ | ❌ | ✔ | ❌ |
| SEED (D) | ✔ | ✔ | ✔ | ✔ | ❌ | ❌ | ❌ | ✔ | ❌ |
| IDEA (D) | ✔ | ✔ | ✔ | ✔ | ❌ | ❌ | ❌ | ✔ | ❌ |
Notes:
- Key/IV Types: All key and IV inputs must be
BYTESLIKEobjects of the correct length for the chosen algorithm/mode. Use theRandom Nonce Generatornode to create secure random values. - Stream Ciphers: Stream ciphers like
ChaCha20andARC4do not use a block mode; selectNone. - GCM: GCM is an authenticated mode and only works with AES in this implementation. It provides both confidentiality and integrity.
- ECB: Electronic Codebook mode is insecure for most uses and should be avoided. It does not use an IV.
- Padding: Block ciphers in modes like CBC and ECB require padding to handle messages that are not a multiple of the block size. Use
AES Key Wrap With Paddingto pad keys to the appropriate length.
Deprecation Warning:
As of cryptography 47.0.0, several legacy primitives were moved to a decrepit module. This includes algorithms like ARC4, Blowfish, CAST5, IDEA, SEED, TripleDES, and Camellia, as well as modes like OFB, CFB, and CFB8. These are considered insecure or sub-optimal and are only provided for compatibility with legacy systems. Users are encouraged to use AES (with GCM or CTR mode) or ChaCha20 for modern applications. For more information, check the latest documentations over at https://cryptography.io/en/47.0.0/.