Security module API (require “security”)
sha256
- Evaluates sha1 hash of an incoming string.
get_all_digest_names
- Returns all symbolic names possible to pass to the digest_by_name.
Edit
Params : No
Edit
fields | type | description |
---|---|---|
array_of_names | array of strings | An array of string names of all available digest methods available. |
Edit
local security = require("security")
local array_of_names = security.get_all_digest_names()
-- Will return: ["md5', 'md4', 'sha1', 'sha224', sha256', ...]
digest_by_name
- Evaluates hash of an incoming string using a digest method specified. To successfully calculate a value the digest name should be listed in an output of get_all_digest_names() function.
Edit
fields | type | required | description |
---|---|---|---|
digestName | string | + | A digest method to calculate. Should be one of available methods. |
data | string | + | Target data to calculate a digest from. |
Edit
fields | type | description |
---|---|---|
hash | string | A digest value calculated, hex representation in lower case format |
Edit
message | description |
---|---|
digest name is empty | The digest name should not be empty |
failed to evaluate ‘digest_by_name’ digest with name ‘ | The unsupported digest name is passed |
input data size is more than N bytes | Input size is too big |
Edit
local security = require("security")
local hash = security.digest_by_name("sha334", "This is a string")
cipher settings
Settings
fields | type | description |
---|---|---|
key | string | Cipher key. Supported key lengths: (), (), (). |
type | string | [opt] Cipher type. The type is only supported for now. |
mode | string | [opt] Supported modes: , , , , , . Default mode: . |
iv | string | [opt] Initialization vector. The empty string by default. |
auto_padding | bool | [opt] Enable auto padding of encrypted/decrypted data. If auto padding is disabled data size must be multiple of 16. It works for , modes only. Another modes doesn’t require data padding. The auto padding is enabled by default. |
encrypt
- Encrypt data with cipher settings.
Edit
fields | type | description |
---|---|---|
cipher | table | Cipher settings |
data | string | Target data for encryption. |
Edit
fields | type | description |
---|---|---|
encrypted_data | string | encrypted data |
Edit
Edit
local security = require("security")
local cipher = {
type = "aes",
key = "StringKeyStringK",
mode = "ofb"
} --string key (size 16 bytes) and empty initialization vector
local encrypted_data = security.encrypt( cipher, "data for encryption" )
Edit
local security = require("security")
local cipher = {
key = "\x17\xC6\x3C\x37\xDE\x19\xCF\x00\x6A\xC9\x15\x1A\x00\x3C\x78\x43",
mode = "cbc"
} --binary key (size 16 bytes) and empty initialization vector
local encrypted_data = security.encrypt( cipher, "data for encryption" )
Edit
local security = require("security")
local cipher = {
key = "\x09\x76\x28\x34\x3f\xe9\x9e\x23\x76\x5c\x15\x13\xac\xcf\x8b\x02",
iv = "\x56\x2e\x17\x99\x6d\x09\x3d\x28\xdd\xb3\xba\x69\x5a\x2e\x6f\x58"
} --binary key (size 16 bytes) and binary initialization vector
local encrypted_data = security.encrypt( cipher, "data for encryption" )
Edit
local security = require("security")
local cipher = {
key = "\x17\xC6\x3C\x37\xDE\x19\xCF\x00\x6A\xC9\x15\x1A\x00\x3C\x78\x43",
iv = "\x56\x2e\x17\x99\x6d\x09\x3d\x28\xdd\xb3\xba\x69\x5a\x2e\x6f\x58",
auto_padding = false
} --disabled auto padding
local encrypted_data = security.encrypt( cipher, "Data must be multiple of 16\x00\x00\x00\x00\x00" )
decrypt
- Decrypt data with cipher settings.
Edit
fields | type | description |
---|---|---|
cipher_id | string | Cipher settings |
data | string | Target data for decryption. |
Edit
fields | type | description |
---|---|---|
decrypted_data | string | decrypted data |
Edit
Edit
local security = require("security")
local cipher = {
type = "aes",
key = "StringKeyStringK",
mode = "ofb"
} --string key (size 16 bytes) and empty initialization vector
local decrypted_data = security.decrypt( cipher, "data for decryption" )
Edit
local security = require("security")
local cipher = {
key = "\x17\xC6\x3C\x37\xDE\x19\xCF\x00\x6A\xC9\x15\x1A\x00\x3C\x78\x43",
mode = "cbc"
} --binary key (size 16 bytes) and empty initialization vector
local decrypted_data = security.decrypt( cipher, "data for decryption" )
Edit
local security = require("security")
local cipher = {
key = "\x09\x76\x28\x34\x3f\xe9\x9e\x23\x76\x5c\x15\x13\xac\xcf\x8b\x02",
iv = "\x56\x2e\x17\x99\x6d\x09\x3d\x28\xdd\xb3\xba\x69\x5a\x2e\x6f\x58"
} --binary key (size 16 bytes) and binary initialization vector
local decrypted_data = security.decrypt( cipher, "data for decryption" )
Edit
local security = require("security")
local cipher = {
key = "\x17\xC6\x3C\x37\xDE\x19\xCF\x00\x6A\xC9\x15\x1A\x00\x3C\x78\x43",
iv = "\x56\x2e\x17\x99\x6d\x09\x3d\x28\xdd\xb3\xba\x69\x5a\x2e\x6f\x58",
auto_padding = false
} --disabled auto padding
--encrypted data is 32 bytes. It's multiple of 16
local encrypted_data = "\xcf\xa5t\x05H\xd5\x8d\c\xf0N\x18t\xa3\xce\x90\xe4Hy\xa7[\x08\xab\xde5/NR\x91'P\x06";
local decrypted_data = security.decrypt( cipher, encrypted_data )
to_base64
- Encrypt data to base64 cipher.
from_base64
- Decrypt data to base64 cipher.
from_hex_string
- Transforms a string that consists of hexadecimal characters to its binary representation. The string should be of even length and should contain only hexadecimal characters in it. Every pair of characters form a single byte in a binary result.
Edit
fields | type | description |
---|---|---|
data | string | Target data to transform. Should contain hexadecimal symbols only and be of even length. |
Edit
type | description |
---|---|
string | A binary representation of an input string |
Edit
message | description |
---|---|
input data size is more than 1000000 bytes | Limits input size up to 1 million bytes |
input data couldn’t be transformed to binary | Input data contains invalid data to convert to a binary representation. It can be not of even length, contain inappropriate symbols. |
Edit
local security = require("security")
local hash = security.sha256( 'Some human-readable string' )
local binary_hash = security.from_hex_string( hash )
How can we help?
A premium WordPress theme with integrated Knowledge Base,
providing 24/7 community based support.