Skip to content

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

js
const crypto = require('crypto');
const digest = crypto.createHash('sha256').update('payload').digest('hex');

API

FunctionParamsReturnsNotes
secure_random(length) / secureRandom(length)length?: numberstringHex output. Default length: 64.
uuid()nonestringUUID string.
createHash(algorithm)algorithm: stringCryptoCalculatorUse update(...).digest(...).
createHmac(algorithm, key)algorithm: string, key: stringCryptoCalculatorUse for signatures/webhooks.
createCipheriv(algorithm, key, iv)stringsCryptoCalculatorUse update(...).final(...).

Practical Examples

js
const crypto = require('crypto');

const signature = crypto
  .createHmac('sha256', Nimbu.Site.env.get('WEBHOOK_SECRET'))
  .update(request.rawBody || '')
  .digest('hex');
js
const crypto = require('crypto');
const token = crypto.secure_random(32); // `secureRandom` alias is also available

Failure 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.