M MY Multiplayer: Wiki
Side
Kind

encodeString

Shared

Encodes or encrypts a text with an algorithm: TEA, AES-128, RSA, Base64, Base32 or zlib.

string|bool encodeString(string algorithm, string data [, table options = nil, function callback = nil])

Parameters

NameTypeDescription
algorithmstring"tea", "aes128", "rsa", "base64", "base32" or "zlib".
datastringThe text to encode.
optionstableA table of options: key, variant or, for zlib, format ("gzip" by default, "zlib", "raw" or a windowBits), compression (0 to 9, 9 by default) and strategy ("default", "filtered", "huffman", "rle", "fixed").default nil
callbackfunctionIf given, the work runs in the background and the function gets the result (or false) when it is done.default nil

Returns

The result (with aes128, the cipher text and the 16-byte initialisation vector decodeString needs). With callback, true right away. false if the options are invalid or the operation failed.

Algorithms

options is required for "tea", "aes128" and "rsa".

Algorithm Options
"tea" Key in key; only its first 16 bytes count.
"aes128" AES-128 in CTR mode; key must be exactly 16 bytes long.
"rsa" key holds the public key to encode and the private key to decode.
"base64" Optional variant = "URL" for the URL-safe alphabet.
"base32" Optional variant = "HEX" for the hexadecimal alphabet.
"zlib" Optional format ("gzip" default, "zlib", "raw" or windowBits), compression (0–9, default 9) and strategy.

Example

local key = "0123456789abcdef"
local cipher, iv = encodeString("aes128", "secret message", { key = key })
local plain = decodeString("aes128", cipher, { key = key, iv = iv })

See also