crypto
The crypto namespace provides essential cryptography and encoding primitives without needing any external C or Python dependencies.
Quick Reference
Section titled “Quick Reference”| Function | Signature | Return Type | Description |
|---|---|---|---|
crypto.uuid | crypto.uuid() | string | Generates a random RFC 4122 v4 UUID string. |
crypto.random_bytes | crypto.random_bytes(n) | string | Generates n cryptographically secure random bytes (hex). |
crypto.sha256 | crypto.sha256(str) | string | Computes SHA-256 hexadecimal digest. |
crypto.sha1 | crypto.sha1(str) | string | Computes SHA-1 hexadecimal digest. |
crypto.md5 | crypto.md5(str) | string | Computes MD5 hexadecimal digest. |
crypto.hmac_sha256 | crypto.hmac_sha256(msg, key) | string | Generates an HMAC-SHA256 signature. |
crypto.base64_encode | crypto.base64_encode(str) | string | Encodes string into Base64 format. |
crypto.base64_decode | crypto.base64_decode(b64) | string | Decodes a Base64 string. |
Detailed Methods
Section titled “Detailed Methods”crypto.uuid()
Section titled “crypto.uuid()”Generates a cryptographically strong UUID version 4:
var id = crypto.uuid();print("Session ID: " + id);crypto.sha256(input)
Section titled “crypto.sha256(input)”Calculates standard 256-bit SHA-2 digest:
var hash = crypto.sha256("password123");print("Hash: " + hash);crypto.hmac_sha256(message, secret_key)
Section titled “crypto.hmac_sha256(message, secret_key)”Produces an HMAC authentication signature using SHA-256:
var payload = "GET /api/v1/orders";var secret = "my_super_secret_key";
var signature = crypto.hmac_sha256(payload, secret);print("API Signature: " + signature);crypto.base64_encode(text) & crypto.base64_decode(encoded)
Section titled “crypto.base64_encode(text) & crypto.base64_decode(encoded)”Fast binary-to-text Base64 conversions:
var raw = "Hello, RayQuiro!";var encoded = crypto.base64_encode(raw);print("Base64: " + encoded);
var decoded = crypto.base64_decode(encoded);print("Restored: " + decoded);crypto.random_bytes(count)
Section titled “crypto.random_bytes(count)”Generates random cryptographically secure hex strings:
var token = crypto.random_bytes(16);print("Csrf Token: " + token);