Skip to content

crypto

The crypto namespace provides essential cryptography and encoding primitives without needing any external C or Python dependencies.


FunctionSignatureReturn TypeDescription
crypto.uuidcrypto.uuid()stringGenerates a random RFC 4122 v4 UUID string.
crypto.random_bytescrypto.random_bytes(n)stringGenerates n cryptographically secure random bytes (hex).
crypto.sha256crypto.sha256(str)stringComputes SHA-256 hexadecimal digest.
crypto.sha1crypto.sha1(str)stringComputes SHA-1 hexadecimal digest.
crypto.md5crypto.md5(str)stringComputes MD5 hexadecimal digest.
crypto.hmac_sha256crypto.hmac_sha256(msg, key)stringGenerates an HMAC-SHA256 signature.
crypto.base64_encodecrypto.base64_encode(str)stringEncodes string into Base64 format.
crypto.base64_decodecrypto.base64_decode(b64)stringDecodes a Base64 string.

Generates a cryptographically strong UUID version 4:

var id = crypto.uuid();
print("Session ID: " + id);

Calculates standard 256-bit SHA-2 digest:

var hash = crypto.sha256("password123");
print("Hash: " + hash);

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);

Generates random cryptographically secure hex strings:

var token = crypto.random_bytes(16);
print("Csrf Token: " + token);