Crypt
The crypt library provides methods for the encryption and decryption of string data.
Behavior and examples documented on this page are based on Script-Ware.
crypt.base64encode
function crypt.base64encode(data: string): string
Encodes a string of bytes into Base64.
data - The data to encode.
local base64 = crypt.base64encode("Hello, World!")
local raw = crypt.base64decode(base64)
print(base64) --> SGVsbG8sIFdvcmxkIQ==
print(raw) --> Hello, World!
crypt.base64decode
Decodes a Base64 string to a string of bytes.
data - The data to decode.
🪲 Compatibility 🔎 RFC
Encrypts an unencoded string using AES encryption. Returns the base64 encoded and encrypted string, and the IV.
If an AES IV is not provided, a random one will be generated for you, and returned as a 2nd base64 encoded string.
The cipher modes are 'CBC', 'ECB', 'CTR', 'CFB', 'OFB', and 'GCM'. The default is 'CBC'.
🪲 Compatibility issues
Too few executors support this function and a reliable example cannot be made.
data - The unencoded content.
key - A base64 256-bit key.
iv - Optional base64 AES initialization vector.
mode - The AES cipher mode.
🪲 Compatibility 🔎 RFC
Decrypts the base64 encoded and encrypted content. Returns the raw string.
The cipher modes are 'CBC', 'ECB', 'CTR', 'CFB', 'OFB', and 'GCM'.
🪲 Compatibility issues
Too few executors support this function and a reliable example cannot be made.
data - The base64 encoded and encrypted content.
key - A base64 256-bit key.
iv - The base64 AES initialization vector.
mode - The AES cipher mode.
crypt.generatebytes
Generates a random sequence of bytes of the given size. Returns the sequence as a base64 encoded string.
size - The number of bytes to generate.
crypt.generatekey
Generates a base64 encoded 256-bit key. The result can be used as the second parameter for the crypt.encrypt and crypt.decrypt functions.
Returns the result of hashing the data using the given algorithm.
Some algorithms include 'sha1', 'sha384', 'sha512', 'md5', 'sha256', 'sha3-224', 'sha3-256', and 'sha3-512'.
data - The unencoded content.
algorithm - A hash algorithm.
Last updated