-
Notifications
You must be signed in to change notification settings - Fork 4
Crypto functions
Sudheer edited this page Mar 11, 2023
·
9 revisions
Set of cryptographic utility functions, built on top of Crypto module of Poco
local evl_crypto = (package.loadlib('libevlcrypto.so','luaopen_libevlcrypto'))();
Generates SHA1 digest for the given text data and optional salt
Parameters:
text: string
salt: string, optional
Return:
digest: string
ERROR:
Exceptions are thrown upon error, which can be caught via mechanism of pcall/xpcall
Generates SHA256 digest for the given text data and optional salt
Parameters:
text: string
salt: string, optional
Return:
digest: string
ERROR:
Exceptions are thrown upon error, which can be caught via mechanism of pcall/xpcall
Generates SHA384 digest for the given text data and optional salt
Parameters:
text: string
salt: string, optional
Return:
digest: string
ERROR:
Exceptions are thrown upon error, which can be caught via mechanism of pcall/xpcall
Generates SHA512 digest for the given text data and optional salt
Parameters:
text: string
salt: string, optional
Return:
digest: string
ERROR:
Exceptions are thrown upon error, which can be caught via mechanism of pcall/xpcall
Generates cryptofraphic digest for the given text based, the digest name can be passed as a preference
further passed ke is used in the process of digest generation.
Parameters:
digest_name: string, valid cryptographic digest name, like SHA256, SHA512
text: strin
key: Key used in generation
raw: boolean, if true the raw digest is returned as a string, else HEX encoded digest is returned
Return:
digest: string, either raw or hex
ERROR:
Exceptions are thrown upon error, which can be caught via mechanism of pcall/xpcall
Generates a symmetric key for encryption/decryption based on input key_name
(e.g. AES256, AES128, 3DES, DES etc...);
Parameters:
key_name: string
Return:
symmetric_cipher_key: handle to key
ERROR:
Exceptions are thrown upon error, which can be caught via mechanism of pcall/xpcall
Generates a symmetric key for encryption/decryption based on input key_size
Parameters:
key_size: number, 128, 256 etc...
Return:
none
symmetric_cipher_key: handle to key
ERROR:
Exceptions are thrown upon error, which can be caught via mechanism of pcall/xpcall
Returns a (public, private) kep-pair given the key length.
Parameters:
key_length: integer, one of 512, 1024, 2048 or 4096
Return:
rsa_key: handle to rsa_key object
ERROR:
Exceptions are thrown upon error, which can be caught via mechanism of pcall/xpcall
Given the rsa_key object, returns the public key in string (base64) format
Parameters:
rsa_key: handle to RSA key
Return:
public_key: string
ERROR:
Exceptions are thrown upon error, which can be caught via mechanism of pcall/xpcall
Given the rsa_key object, returns the private key in string (base64) format
Parameters:
rsa_key: handle to RSA key
Return:
private_key: string
ERROR:
Given a public key in string format (typically read from a file),
returns the rsa_key object
Parameters:
public_key: string
Return:
rsa_key: handle to rsa_key object
ERROR:
Exceptions are thrown upon error, which can be caught via mechanism of pcall/xpcall
Given a private key in string format (typically read from a file),
returns the rsa_key object
Parameters:
private_key: string
Return:
rsa_key: handle to rsa_key object
ERROR:
Exceptions are thrown upon error, which can be caught via mechanism of pcall/xpcall
Encrypts a symmetric key with using the public key in the rsa_key object
Parameters:
symm_key: symmetric key handle
rsa_key: RSA key handle
Return:
length: integer, Length of the encrypted buffer
buffer: lightuserdata, Encripted buffer
ERROR:
Exceptions are thrown upon error, which can be caught via mechanism of pcall/xpcall
Decrypts the encrypted symmetric key, using the private key in the rsa_key
Parameters:
cipher_text: userdata, Encrypted symmetric key
rsa_key: userdata, handle to rsa_key object
Return:
symm_key: userdata, symm_key object
ERROR:
Exceptions are thrown upon error, which can be caught via mechanism of pcall/xpcall
Decrypts the encrypted symmetric key, using the private key in the rsa_key
Parameters:
cipher_text: userdata, Encrypted symmetric key
lenght: integer, length of the ciphertext buffer
rsa_key: userdata, handle to rsa_key object
Return:
symm_key: userdata, symm_key object
ERROR:
Exceptions are thrown upon error, which can be caught via mechanism of pcall/xpcall
Decrypts the encrypted symmetric key, using the private key in the rsa_key
Parameters:
b64_cipher_text: string, Encrypted symmetric key in base64 format
rsa_key: userdata, handle to rsa_key object
Return:
symm_key: userdata, symm_key object
ERROR:
Exceptions are thrown upon error, which can be caught via mechanism of pcall/xpcall
Encrypts the given plain text, using the key
Parameters:
plain_text: string
key: cipher_key handle
Return:
length: integer, size of the buffer
cipher_text: userdata
ERROR:
Exceptions are thrown upon error, which can be caught via mechanism of pcall/xpcall
Decrypts the ciphertext using the key and returns plaintext
Parameters:
cipher_text: userdata
key: symm_key
Return:
plain_text: string
ERROR:
Exceptions are thrown upon error, which can be caught via mechanism of pcall/xpcall
Decrypts the ciphertext, in the form of a memory buffer along with length using the key and returns plaintext
Parameters:
cipher_text: userdata
bufferlen: integer, size of userdata
key: symm_key
Return:
plain_text: string
ERROR:
Exceptions are thrown upon error, which can be caught via mechanism of pcall/xpcall
Decrypts the input ciphertext n base64 format, using the key and returns plaintext
Parameters:
b64_cipher_text: string
key: symm_key
Return:
plain_text: string
ERROR:
Exceptions are thrown upon error, which can be caught via mechanism of pcall/xpcall