n8n crypto tools for encryption and decryption operations
npm install n8n-nodes-crypttools
Operation: Encrypt
Algorithm: AES-256-CBC
Key: mySecretKey
Input Data: Hello, World!
Key Processing: SHA256 hash
Input Format: UTF-8 string
Output Format: Base64
`
解密:
`
Operation: Decrypt
Algorithm: AES-256-CBC
Key: mySecretKey
Input Data: [加密后的Base64数据]
Key Processing: SHA256 hash
Input Format: Base64
Output Format: UTF-8 string
`
$3
`
Operation: Hash
Hash Algorithm: sha256
Input Data: Hello, World!
Input Format: UTF-8 string
Output Format: Hex
`
$3
`
Operation: HMAC
Hash Algorithm: sha256
Key: mySecretKey
Input Data: Hello, World!
Input Format: UTF-8 string
Output Format: Hex
`
$3
`
Operation: Key derivation
Key Derivation Method: PBKDF2
Key: password123
Key Length: 32
Iterations: 100000
Output Format: Hex
`
兼容原有代码
此节点可以完美替代原生 Node.js 中的 crypto 模块功能。例如,原来的这段代码:
`javascript
const crypto = require('crypto');
class AESCipher {
constructor(key) {
const hash = crypto.createHash('sha256');
hash.update(key);
this.key = hash.digest();
}
encrypt(content, ivKey) {
ivKey = ivKey ? Buffer.from(ivKey) : crypto.randomBytes(16);
const cipher = crypto.createCipheriv('aes-256-cbc', this.key, ivKey);
let encrypted = cipher.update(content);
encrypted = Buffer.concat([encrypted, cipher.final()]);
return Buffer.concat([ivKey, encrypted]).toString('base64');
}
decrypt(encrypt) {
const encryptBuffer = Buffer.from(encrypt, 'base64');
const ivKey = encryptBuffer.slice(0, 16);
const encrypted = encryptBuffer.slice(16);
const decipher = crypto.createDecipheriv('aes-256-cbc', this.key, ivKey);
let decrypted = decipher.update(encrypted);
decrypted = Buffer.concat([decrypted, decipher.final()]);
return decrypted.toString();
}
}
`
现在可以通过配置 CryptoTools 节点来实现相同的功能:
- Operation: Encrypt 或 Decrypt
- Algorithm: AES-256-CBC
- Key Processing: SHA256 hash
- Input Format: UTF-8 string
- Output Format: Base64
安装
1. 在 n8n 中打开 "Settings" -> "Community Nodes"
2. 输入包名: n8n-nodes-crypttools
3. 点击 "Install"
开发
`bash
克隆仓库
git clone
cd n8n-nodes-crypttools
安装依赖
npm install
构建项目
npm run build
代码检查
npm run lint
自动修复lint问题
npm run lintfix
``