Module Reference
crypto
Hashing, HMAC, random token, and cipher helpers for Cloud Code.
What This Adds In Cloud Code
- Built-in hash/HMAC helpers exposed in JS style.
- Predictable random token and UUID generation.
- Cipher helper with explicit algorithm/digest controls.
Quick Start
const crypto = require('crypto');
const digest = crypto.createHash('sha256').update('payload').digest('hex');API
| Function | Params | Returns | Notes |
|---|---|---|---|
secure_random(length) / secureRandom(length) | length?: number | string | Hex output. Default length: 64. |
uuid() | none | string | UUID string. |
createHash(algorithm) | algorithm: string | CryptoCalculator | Use update(...).digest('hex' | 'base64'). |
createHmac(algorithm, key) | algorithm: string, key: string | CryptoCalculator | Use for signatures/webhooks. |
createCipheriv(algorithm, key, iv) | strings | CryptoCalculator | Use update(...).final(...). |
Practical Examples
const crypto = require('crypto');
// In a route, req.body is the raw request body
const signature = crypto
.createHmac('sha256', Nimbu.Site.env.get('WEBHOOK_SECRET'))
.update(req.body || '')
.digest('hex');For a full example that checks Nimbu's own X-Nimbu-Signature header, see Verify Nimbu Webhook Signatures.
const crypto = require('crypto');
const token = crypto.secure_random(32); // `secureRandom` alias is also availableFailure Modes & Gotchas
- Unsupported algorithms/digests can return empty output.
- Keep keys in
Nimbu.Site.env, never hardcoded. - Compare signatures in constant-time logic when possible.