You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
decrypt : Uses AES encryption to decrypt the input cyphertext.
encrypt : Uses AES encryption to encrypt the input plaintext.
This namespace provides access to OS-level cryptography routines. Most of the inputs and outputs are Lua strings, but some contain binary data and some contain hexadecimal digits (ASCII) representing binary data. The library also provides routines to convert between these two formats efficiently.
crypto.conv_bin_to_chars
Converts a binary string to the equivalent string of hexadecimal digits.
Input Type
Description
string
A string of binary values between 0 and 255.
Output Type
Description
string
A string of pairs of hexadecimal digits that correspond to the binary data.
localbin_string="\x53\x4d\x3a\xf4"localchars_string=crypto.conv_bin_to_chars(bin_string)
print (chars_string) -- prints "534d3af4"
crypto.conv_chars_to_bin
Converts a string of hexadecimal digits to the equivalent string of binary values. Any characters that are not hexadecimal digits are skipped.
Input Type
Description
string
A string of pairs of hexadecimal digits ('0'-'9' and 'a'-'f').
Output Type
Description
string
A string of binary values corresponding to each pair of hexadecimal digits.
Uses PBKDF2 with SHA-256 to create a key appropriate for encryption and decryption. It is important to choose a key seed that is random and difficult to guess. A random password generator is one effective approach.
Input Type
Description
string
The seed (as binary bytes). This corresponds to a passphrase or other sequence of secret characters.
string
Key salt (as binary bytes). Calculate new key salt every time you encrypt with the seed.
Output Type
Description
string
The key represented as binary bytes.
localseed="my secret password" -- choose something less guessable than thislocalsalt=crypto.calc_randomized_data() -- you will need this to decryptlocalkey=crypto.calc_crypto_key(seed, salt)
crypto.encrypt
Uses AES encryption to encrypt the input plaintext. After encryption you will have three separate binary strings that are needed in order to decrypt:
cyphertext (the encrypted text)
key salt (used to recreate the encryption key)
iv (used to initialize the encryption buffer)
You can safely store these in the clear anywhere that makes sense for your application. The seed value should be stored securely and separately from the program. One approach might be to put it in an environment variable when your program runs.
Input Type
Description
string
The encyption key (binary string)
string
The plaintext to encrypt
Output Type
Description
string
The encrypted cyphertext (binary string)
string
The iv used to initialize the encryption buffer (binary string)
localplaintext="The plaintext to encrypt"localseed="my secret password" -- choose something less guessable than thislocalsalt=crypto.calc_randomized_data() -- you will need this to decryptlocalkey=crypto.calc_crypto_key(seed, salt)
localcyphertext, iv=crypto.encrypt(key, plaintext)
-- to decrypt the cyphertext, you will need the salt and the iv, both of which-- you can safely store in the clear alongside the cyphertext.
crypto.decrypt
Uses AES encryption to decrypt the input cyphertext. In addition to the cyphertext, you
need the key salt and iv that were generated as part of the encryption process.
Input Type
Description
string
The encyption key (binary string)
string
The cyphertext to decrypt (binary string)
string
The iv from the call to encrypt (binary string)
Output Type
Description
string
The decrypted plaintext.
localcyphertext-- retrieved from wherever you stored it after encryptionlocalsalt-- retrieved from wherever you stored it after encryptionlocaliv-- retrieved from wherever you stored it after encryptionlocalseed="my secret password" -- one way to get this value might be an environment variablelocalkey=crypto.calc_crypto_key(seed, salt)
localplaintext=crypto.decrypt(key, cyphertext, iv)