Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
7d965b2b
Commit
7d965b2b
authored
Jan 09, 2016
by
Marcel Stör
Browse files
Small doc-syntax fixes
parent
fe3a6490
Changes
1
Hide whitespace changes
Inline
Side-by-side
docs/en/modules/crypto.md
View file @
7d965b2b
...
...
@@ -6,104 +6,105 @@ The crypto modules provides various functions for working with cryptographic alg
Compute a cryptographic hash of a Lua string.
####Syntax
####
Syntax
`hash = crypto.hash(algo, str)`
####Parameters
-
`algo`
: T
he hash algorithm to use, case insensitive string
####
Parameters
`algo`
t
he hash algorithm to use, case insensitive string
Supported hash algorithms are:
-
MD2 (not available by default, has to be explicitly enabled in user_config.h)
-
MD5
-
SHA1
-
SHA256, SHA384, SHA512 (unless disabled in user_config.h)
####Returns
A binary string containing the message digest. To obtain the textual version (ASCII hex characters), please use
`crypto.toHex()`
.
-
MD2 (not available by default, has to be explicitly enabled in
`app/include/user_config.h`
)
-
MD5
-
SHA1
-
SHA256, SHA384, SHA512 (unless disabled in
`app/include/user_config.h`
)
####Example
#### Returns
A binary string containing the message digest. To obtain the textual version (ASCII hex characters), please use
[
`crypto.toHex()`
](
#cryptotohex
)
.
#### Example
```
lua
print
(
crypto
.
toHex
(
crypto
.
hash
(
"sha1"
,
"abc"
)))
```
__
_
## crypto.hmac()
Compute a HMAC (Hashed Message Authentication Code) signature for a Lua string.
Compute a
[
HMAC
](
https://en.wikipedia.org/wiki/Hash-based_message_authentication_code
)
(
Hashed
Message Authentication Code) signature for a Lua string.
## Syntax
##
## Syntax
`signature = crypto.hmac(algo, str, key)`
####Parameters
-
algo
:
hash algorithm to use, case insensitive string
-
str
:
data to calculate the hash for
-
key
:
key to use for signing, may be a binary string
####
Parameters
-
`
algo
`
hash algorithm to use, case insensitive string
-
`
str
`
data to calculate the hash for
-
`
key
`
key to use for signing, may be a binary string
Supported hash algorithms are:
-
MD2 (not available by default, has to be explicitly enabled in user_config.h)
-
MD5
-
SHA1
-
SHA256, SHA384, SHA512 (unless disabled in user_config.h)
####Returns
A binary string containing the HMAC signature. Use
`crypto.toHex()`
to obtain the textual version.
-
MD2 (not available by default, has to be explicitly enabled in
`app/include/user_config.h`
)
-
MD5
-
SHA1
-
SHA256, SHA384, SHA512 (unless disabled in
`app/include/user_config.h`
)
####Example
#### Returns
A binary string containing the HMAC signature. Use
[
`crypto.toHex()`
](
#cryptotohex
)
to obtain the textual version.
#### Example
```
lua
print
(
crypto
.
toHex
(
crypto
.
hmac
(
"sha1"
,
"abc"
,
"mysecret"
)))
```
__
_
## crypto.mask()
Applies an XOR mask to a Lua string. Note that this is not a proper cryptographic mechanism, but some protocols may use it nevertheless.
####Syntax
masked =
crypto.mask
(message, mask)
####
Syntax
`
crypto.mask(message, mask)
`
####Parameters
-
message
:
message to mask
-
mask
=
the mask to apply, repeated if shorter than the message
####
Parameters
-
`
message
`
message to mask
-
`
mask
`
the mask to apply, repeated if shorter than the message
####Returns
The masked message, as a binary string. Use
`crypto.toHex()`
to get a textual representation of it.
####
Returns
The masked message, as a binary string. Use
[
`crypto.toHex()`
](
#cryptotohex
)
to get a textual representation of it.
####Example
####
Example
```
lua
print
(
crypto
.
toHex
(
crypto
.
mask
(
"some message to obscure"
,
"X0Y7"
)))
```
__
_
## crypto.toHex()
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.
## crypto.toBase64()
####Syntax
`hexstr = crypto.toHex(binary)`
Provides a Base64 representation of a (binary) Lua string.
#### Syntax
`b64 = crypto.toBase64(binary)`
####Parameters
-
`binary`
:
input string to
get hex representation for
####
Parameters
`binary`
input string to
Base64 encode
####Return
s
A
n ASCII hex
string.
####
Return
A
Base64 encoded
string.
####Example
####
Example
```
lua
print
(
crypto
.
to
Hex
(
crypto
.
hash
(
"sha1"
,
"abc"
)))
print
(
crypto
.
to
Base64
(
crypto
.
hash
(
"sha1"
,
"abc"
)))
```
__
_
## crypto.toBase64()
Provides a Base64 representation of a (binary) Lua string.
## crypto.toHex()
####Syntax
`b64 = crypto.toBase64(binary)`
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.
####
Parameters
-
`binary`
: input string to Base64 encode
####
Syntax
`hexstr = crypto.toHex(binary)`
####Return
A Base64 encoded string.
#### Parameters
`binary`
input string to get hex representation for
#### Returns
An ASCII hex string.
####Example
####
Example
```
lua
print
(
crypto
.
to
Base64
(
crypto
.
hash
(
"sha1"
,
"abc"
)))
print
(
crypto
.
to
Hex
(
crypto
.
hash
(
"sha1"
,
"abc"
)))
```
__
_
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment