2016-02-21 05:18:27 +01:00
|
|
|
# encoder Module
|
2016-03-05 10:47:01 +01:00
|
|
|
| Since | Origin / Contributor | Maintainer | Source |
|
|
|
|
| :----- | :-------------------- | :---------- | :------ |
|
2019-01-13 22:01:57 +01:00
|
|
|
| 2016-02-26 | [Terry Ellison](https://github.com/TerryE) | [Terry Ellison](https://github.com/TerryE) | [encoder.c](../../app/modules/encoder.c)|
|
2016-02-21 05:18:27 +01:00
|
|
|
|
|
|
|
The encoder modules provides various functions for encoding and decoding byte data.
|
|
|
|
|
|
|
|
## encoder.toBase64()
|
|
|
|
|
|
|
|
Provides a Base64 representation of a (binary) Lua string.
|
|
|
|
|
|
|
|
#### Syntax
|
|
|
|
`b64 = encoder.toBase64(binary)`
|
|
|
|
|
|
|
|
#### Parameters
|
|
|
|
`binary` input string to Base64 encode
|
|
|
|
|
|
|
|
#### Return
|
|
|
|
A Base64 encoded string.
|
|
|
|
|
|
|
|
#### Example
|
|
|
|
```lua
|
2016-02-26 01:44:33 +01:00
|
|
|
print(encoder.toBase64(crypto.hash("sha1","abc")))
|
2016-02-21 05:18:27 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
## encoder.fromBase64()
|
|
|
|
|
2016-02-26 01:44:33 +01:00
|
|
|
Decodes a Base64 representation of a (binary) Lua string back into the original string. An error is
|
|
|
|
thrown if the string is not a valid base64 encoding.
|
2016-02-21 05:18:27 +01:00
|
|
|
|
|
|
|
#### Syntax
|
2020-08-22 10:30:29 +02:00
|
|
|
`binary_string = encoder.fromBase64(b64)`
|
2016-02-21 05:18:27 +01:00
|
|
|
|
|
|
|
#### Parameters
|
2019-02-17 19:26:29 +01:00
|
|
|
`b64` Base64 encoded input string
|
2016-02-21 05:18:27 +01:00
|
|
|
|
|
|
|
#### Return
|
|
|
|
The decoded Lua (binary) string.
|
|
|
|
|
|
|
|
#### Example
|
|
|
|
```lua
|
|
|
|
print(encoder.fromBase64(encoder.toBase64("hello world")))
|
|
|
|
```
|
|
|
|
|
|
|
|
## encoder.toHex()
|
|
|
|
|
2016-02-26 01:44:33 +01:00
|
|
|
Provides an ASCII hex representation of a (binary) Lua string. Each byte in the input string is
|
|
|
|
represented as two hex characters in the output.
|
2016-02-21 05:18:27 +01:00
|
|
|
|
|
|
|
#### Syntax
|
|
|
|
`hexstr = encoder.toHex(binary)`
|
|
|
|
|
|
|
|
#### Parameters
|
|
|
|
`binary` input string to get hex representation for
|
|
|
|
|
|
|
|
#### Returns
|
|
|
|
An ASCII hex string.
|
|
|
|
|
|
|
|
#### Example
|
|
|
|
```lua
|
|
|
|
print(encoder.toHex(crypto.hash("sha1","abc")))
|
|
|
|
```
|
|
|
|
|
|
|
|
## encoder.fromHex()
|
|
|
|
|
2016-02-26 01:44:33 +01:00
|
|
|
Returns the Lua binary string decode of a ASCII hex string. Each byte in the output string is
|
2019-02-17 19:26:29 +01:00
|
|
|
represented as two hex characters in the input. An error is thrown if the string is not a
|
2016-02-26 01:44:33 +01:00
|
|
|
valid base64 encoding.
|
2016-02-21 05:18:27 +01:00
|
|
|
|
|
|
|
#### Syntax
|
2016-02-26 01:44:33 +01:00
|
|
|
`binary = encoder.fromHex(hexstr)`
|
2016-02-21 05:18:27 +01:00
|
|
|
|
|
|
|
#### Parameters
|
|
|
|
`hexstr` An ASCII hex string.
|
|
|
|
|
|
|
|
#### Returns
|
|
|
|
Decoded string of hex representation.
|
|
|
|
|
|
|
|
#### Example
|
|
|
|
```lua
|
2019-01-20 12:46:53 +01:00
|
|
|
print(encoder.fromHex("6a6a6a"))
|
2016-02-21 05:18:27 +01:00
|
|
|
```
|