Cryptography & Hashing
Built-in cryptographic primitives for encoding, hashing, HMAC authentication, and symmetric AES-256 encryption.
local encoded = base64.encode(data: string, url_safe?: boolean) --> stringlocal decoded = base64.decode(data: string) --> stringurl_safe: Replaces standard+/characters with URL-safe-_.base64.decodeautomatically ignores whitespace and newlines.
MD5 Hashing
Section titled βMD5 Hashingβmd5.sum(data) --> raw 16 bytes stringmd5.sumhexa(data) --> 32-character lowercase hex stringmd5.binary(data) --> alias of summd5.hex(data) --> alias of sumhexamd5.tohex(bytes) --> converts raw bytes string to hex stringsha1(data) --> 40-character hex string (callable table)sha1.hex(data) --> 40-character hex stringsha1.binary(data) --> raw 20 bytes stringsha1.hmac(key, message) --> hex stringsha1.hmac_binary(key, msg) --> raw 20 bytes HMAC digestSHA-256
Section titled βSHA-256βsha256.hex(data) --> 64-character hex stringsha256.binary(data) --> raw 32 bytes stringsha256.hmac(key, message) --> hex stringsha256.hmac_binary(key, msg) --> raw 32 bytes HMAC digestAES-256 Encryption (aes)
Section titled βAES-256 Encryption (aes)βNative AES-256 encryption with PKCS#7 padding.
-- Electronic Codebook (ECB) Mode (Requires 32-byte key)local cipher = aes.encrypt(key: string, plaintext: string) --> string | nillocal plain = aes.decrypt(key: string, ciphertext: string) --> string | nil
-- Cipher Block Chaining (CBC) Mode (Requires 32-byte key & 16-byte IV)local cipher = aes.encrypt(key: string, plaintext: string, iv: string) --> string | nillocal plain = aes.decrypt(key: string, ciphertext: string, iv: string) --> string | nilEncrypting & Decrypting Data
Section titled βEncrypting & Decrypting Dataβlocal secret_key = sha256.binary("my_secure_script_password")local config_data = json.stringify({ user = "alice", premium = true })
-- Encryptlocal encrypted_blob = aes.encrypt(secret_key, config_data)
-- Decryptlocal decrypted_json = aes.decrypt(secret_key, encrypted_blob)if decrypted_json then local restored_data = json.parse(decrypted_json) print("Decrypted User: " .. restored_data.user)end