Crypto Js

JavaScript library of crypto standards.

Crypto Js

AI-generated

Overview

This node provides a variety of cryptographic operations using JavaScript libraries and Node.js crypto features. It supports encrypting and decrypting strings with passphrases or private/public keys, signing data, verifying signatures, base64 decoding, and creating encrypted symmetric keys. This node is useful in scenarios where secure data handling is required within an n8n workflow, such as protecting sensitive information, validating data authenticity, or managing encryption keys.

Practical examples include:

  • Encrypting user input before storing it in a database.
  • Decrypting received encrypted messages for processing.
  • Signing data to ensure integrity and authenticity.
  • Verifying signatures on incoming data to confirm source validity.
  • Base64 decoding encoded data for further use.

Properties

Name Meaning
Action The cryptographic operation to perform. Options: Encrypt, Encrypt Private, Sign, Encrypted Symmetric Key, Decrypt, Decrypt Public, Base64 Decode, Verify
Key Type (Only for Verify action) Selects the key type used for verification. Options: Private, Certificate
Certificate (Required if Key Type is Certificate) The certificate string used to verify the input value
Signature (Required for Verify action) The signature string used to verify the input value
Custom Passphrase (For Encrypt and Decrypt actions) A passphrase to encrypt/decrypt the input value. If empty, uses the passphrase from credentials
Input Value The string or object to be processed by the selected action (e.g., to encrypt, decrypt, sign)
Encrypt Output Type (For Sign and Encrypt Private actions) Format of the output. Options: Base64, Hex
Decrypt Output Type (For Decrypt and Decrypt Public actions) Format of the decrypted output. Options: String, Json
Output Property Name The name of the property in the output JSON where the result will be stored

Output

The node outputs an array of items, each containing a JSON object with the result of the cryptographic operation stored under the specified output property name. For example, if the output property name is "data", the output JSON will have a field "data" containing the encrypted, decrypted, signed, or verified result.

If the operation involves binary data (such as keys or signatures), this data is handled internally but not explicitly output as binary in the node's output.

Dependencies

  • Requires an API key credential that provides at least a passphrase and/or private key depending on the operation.
  • Uses the crypto-js library for AES encryption/decryption.
  • Uses the node-rsa library for RSA key operations (encrypt, decrypt, sign, verify).
  • Uses Node.js built-in crypto module for X509 certificate parsing when verifying with certificates.

Troubleshooting

  • Missing Passphrase or Private Key: Operations like encrypt, decrypt, sign, and verify require either a passphrase or private key. Ensure these are provided either via credentials or custom input.
  • Invalid Input Format: Input values can be strings or objects; objects are stringified before processing. Invalid JSON strings during decryption with JSON output type may cause errors.
  • Incorrect Output Type: Selecting JSON output type for decryption requires the decrypted string to be valid JSON.
  • Verification Failures: When verifying signatures, ensure the correct key type and matching certificate or key are used.
  • Base64 Decoding Errors: Input must be valid base64 encoded strings.

Common error messages:

  • "Passphrase is required" — Provide a passphrase either in credentials or as a custom passphrase.
  • "Private key is required" — Provide a private key in credentials.
  • JSON parse errors during decryption — Check that the decrypted content is valid JSON if JSON output type is selected.

Links and References

Discussion