Overview
This node performs encryption and decryption of string data using the SM2 cryptographic algorithm, which is a public key cryptography standard widely used in certain regions. It can be used to securely encrypt sensitive information before storage or transmission, or decrypt previously encrypted data.
Common scenarios include:
- Encrypting user data fields such as personal identifiers or confidential notes.
- Decrypting received encrypted messages or files for further processing.
- Integrating with systems that require SM2-based cryptography for compliance or interoperability.
For example, you might use this node to encrypt a JSON object containing user details before sending it to an external service, or decrypt incoming encrypted payloads from a partner system.
Properties
| Name | Meaning |
|---|---|
| Operation | Choose between "Encrypt" (to encrypt input data) or "Decrypt" (to decrypt input data). |
| Token (Key) | The cryptographic key: a public key for encryption or a private key for decryption. |
| Input Field Name | The name of the field in the input data whose value will be encrypted or decrypted. |
Output
The node outputs a JSON object with the following structure depending on the operation:
Encrypt:
{ "ciphertext": "04..." // The encrypted string prefixed with "04" }The ciphertext is a hexadecimal string representing the encrypted data.
Decrypt:
If decryption succeeds and the plaintext is valid JSON, the output is the parsed JSON object.
If the plaintext is not valid JSON, the output contains:{ "error": { /* error details from JSON parsing */ }, "plaintext": "..." // The decrypted string }In case of any error during encryption or decryption, the output will contain:
{ "error": "Error message describing what went wrong" }
No binary data output is produced by this node.
Dependencies
- This node depends on the
sm-cryptolibrary, which implements the SM2 cryptographic algorithm. - Requires a valid cryptographic key (public key for encryption, private key for decryption).
- No additional environment variables or external API services are required.
Troubleshooting
- Invalid Key Errors: Using an incorrect or malformed key will cause encryption/decryption to fail. Ensure the key matches the expected format for SM2 keys.
- Decryption Failures: If the ciphertext does not start with the expected prefix
"04"or is corrupted, decryption will fail. - JSON Parsing Errors on Decrypt: If the decrypted plaintext is not valid JSON, the node returns an error object along with the raw plaintext. This is normal if the original data was not JSON.
- Empty or Missing Input Field: If the specified input field does not exist or is empty, the node may throw errors or produce invalid output.
- General Error Handling: Any unexpected errors during processing are caught and returned in the output's
errorfield for easier debugging.
Links and References
- SM2 Cryptography Algorithm - Wikipedia
- sm-crypto GitHub Repository (for more details on the underlying library)