# decodeString (Shared)

> Decodes or decrypts a text `encodeString` produced.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Shared
- **Category**: Data and utilities
- **URL**: https://wiki.mymp.gg/en/decodeString

## Syntax

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

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `algorithm` | `string` | `"tea"`, `"aes128"`, `"rsa"`, `"base64"`, `"base32"` or `"zlib"`. |
| `data` | `string` | The text to decode. |
| `options` | `table` | A table of options: `key`, `iv` (for `aes128`, what `encodeString` returned), `variant` or, for zlib, `format` (without it, zlib or gzip is detected). *(default: `nil`)* |
| `callback` | `function` | If given, the work runs in the background and the function gets the result (or `false`) when it is done. *(default: `nil`)* |

## Returns

The original text. 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` (16 bytes) and `iv` (the 16-byte IV returned by `encodeString`). |
| `"rsa"`    | `key` holds the private key to decode (matching the public key used to encode).             |
| `"base64"` | Optional `variant = "URL"` for the URL-safe alphabet.                                       |
| `"base32"` | Optional `variant = "HEX"` for the hexadecimal alphabet.                                    |
| `"zlib"`   | Optional `format` (without it, zlib or gzip is detected automatically).                     |

## Example

```lua
encodeString("zlib", fileGetContents("map.json"), { compression = 6 }, function(packed)
    if packed then
        print("compressed to " .. #packed .. " bytes")
    end
end)
```

## See also

- [encodeString (Shared)](https://wiki.mymp.gg/en/encodeString.md): Encodes or encrypts a text with an algorithm: TEA, AES-128, RSA, Base64, Base32 or zlib.
- [hash (Shared)](https://wiki.mymp.gg/en/hash.md): Hashes a text: MD5, SHA-1, SHA-2 or an HMAC.
