GPG icon

GPG

Use GPG to encrypt or decrypt data

Overview

This node provides GPG (GNU Privacy Guard) encryption and decryption capabilities within an n8n workflow. It allows users to either encrypt or decrypt data supplied as plain text strings or binary files using a provided GPG key credential.

Common scenarios where this node is beneficial include:

  • Securely encrypting sensitive information before storing or transmitting it.
  • Decrypting received encrypted messages or files for further processing.
  • Automating cryptographic operations in workflows that handle confidential data.

Practical examples:

  • Encrypting a text message before sending it via email.
  • Decrypting an encrypted file downloaded from a secure source.
  • Adding custom metadata alongside encrypted text for audit purposes.

Properties

Name Meaning
Type Choose the input data type: File or String
Text The plain text string to encrypt or decrypt (shown only if Type = String)
Binary Property The name of the binary property containing the file data to encrypt or decrypt (default: "data") (shown only if Type = File)
Output Property The name of the binary property to store the output encrypted/decrypted file (default: "encrypted" for encryption, "decrypted" for decryption) (shown only if Type = File)
Add Additional Properties Whether to add extra user-defined properties to the output JSON object (boolean, shown only if Type = String)
Additional Properties A JSON object with any additional data to add to the output when working with string input (shown only if Add Additional Properties is true and Type = String)

Output

The node outputs JSON data structured differently depending on the operation and input type:

  • For string input:

    • On encryption: { encrypted: <encrypted_string> }
    • On decryption: { decrypted: <decrypted_string> }
    • If additional properties are enabled, these are included inside an additionalProperties field alongside the encrypted/decrypted data.
  • For file input:

    • The output is binary data stored in the specified output binary property.
    • Encrypted files have .gpg extension and MIME type application/pgp-encrypted.
    • Decrypted files retain their original filename and MIME type.
    • The binary data contains the encrypted or decrypted file content accordingly.

Dependencies

  • Requires a valid GPG key credential with the private or public key and passphrase as applicable.
  • Uses the openpgp library for cryptographic operations.
  • No external API calls beyond the use of the GPG key credential.
  • The node expects proper configuration of credentials in n8n to access the GPG keys securely.

Troubleshooting

  • Common issues:

    • Incorrect or missing GPG key credential will cause failures in encryption/decryption.
    • Providing wrong passphrase for private key during decryption will result in errors.
    • Input binary property not found or empty will cause assertion errors.
    • Output binary property name conflicts or missing names may cause unexpected results.
  • Error messages and resolutions:

    • "Error reading key": Check that the GPG key credential is correctly configured and valid.
    • "Failed to decrypt message": Verify the private key and passphrase are correct.
    • "Binary data not found": Ensure the specified binary property exists and contains data.
    • To continue processing despite errors, enable the node's "Continue On Fail" option.

Links and References

Discussion