ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Shared functions
  3. encodeString

Function

encodeString

Server and clientMiscellaneousIdentical to MTA:SA

Encrypts, encodes or compresses text. Works on the server and on the client. Algorithms: tea (raw TEA bytes, no base64), aes128 (the key must be exactly 16 characters; it also returns a random iv needed to decrypt), rsa (a public key from generateKeyPair), base64 (variant url), base32 (the Crypto++ alphabet, variant hex = RFC 4648 base32hex), zlib (format gzip, zlib or raw, level 0-9, strategy). With base64, base32 and zlib the options table can be left out. With a callback the result goes to it in the next frame and the function returns true.

Syntax

string encodeString(string algorithm, string input [, table options, function callback])

Arguments

algorithmstring
"tea", "aes128", "rsa", "base64", "base32" or "zlib".
inputstring
The data.
optionstable, optional
tea/aes128/rsa: { key = "..." }; base64: { variant = "url" }; base32: { variant = "hex" }; zlib: { format = "gzip"|"zlib"|"raw" or windowBits, compression = 0-9, strategy = "default"|"filtered"|"huffman"|"rle"|"fixed" } (default gzip, 9).
callbackfunction, optional
The function gets the result (with aes128 also the iv).

Returns

The result (with aes128 also the iv) or false and a warning.

Example

local key = "0123456789abcdef"
local data, iv = encodeString("aes128", "tajne dane", { key = key })
local plain = decodeString("aes128", data, { key = key, iv = iv })

See also