Corona HTML5 Crypto Plugin similar to standard crypto lib. Includes additional encryption methods.
👷 Built with Corona HTML5 Node Kit.
Add crypto_js.js and crypto.lua to the root of your project.
local crypto = require("crypto")
Generates the message digest (the hash) of the input string.
crypto.digest( algorithm, data [, raw] )
Arguments
name | description | type | required |
---|---|---|---|
algorithm | A constant specifying the hashing algorithm (see Constants). | Constant | Y |
data | The input string. | String | Y |
raw | Set to true for binary output, or false for hexadecimal string (default). |
Boolean | N |
Example
local crypto = require( "crypto" )
local hash = crypto.digest( crypto.md5, "Corona HTML5 Rocks!" )
print( hash ) --> b34ce2675b10580bf9f0d6018c72579c
Computes HMAC (Key-Hashing for Message Authentication Code) of the string and returns it.
crypto.hmac( algorithm, data, key [, raw] )
Arguments
name | description | type | required |
---|---|---|---|
algorithm | A constant specifying the hashing algorithm (see Constants). | Constant | Y |
data | The input string. | String | Y |
key | String to use as the seed for the HMAC generation. | String | Y |
raw | Set to true for binary output, or false for hexadecimal string (default). |
Boolean | N |
Example
local crypto = require( "crypto" )
local hash = crypto.hmac( crypto.md5, "Corona HTML5 Rocks!", "SomeKey" )
print( hash ) --> 1341b82ca266c77f77b27a318508a481
Encrypts a string value using a passphrase. Defaults to AES cipher.
crypto.encrypt( data, passphrase [, cipher] )
Arguments
name | description | type | required |
---|---|---|---|
data | The input data to encrypt. | String | Y |
passphrase | The passphrase string. | String | Y |
cipher | A constant specifying the cipher to use. Defaults to AES. (see Constants). | Constant | N |
Example
local crypto = require( "crypto" )
local encrypted = crypto.encrypt( "Corona HTML5 Rocks!", "passphrase" )
print( encrypted ) --> U2FsdGVkX19YaYWtxaJQJZ9LYoIFsCJS7pLF5vjHs+Q9v0c8evHoGWJ1dbYsUOKG
Decrypts an encrypted value using a passphrase. Defaults to AES cipher.
crypto.decrypt( data, passphrase [, cipher] )
Arguments
name | description | type | required |
---|---|---|---|
data | The input data to decrypt. | String | Y |
passphrase | The passphrase string. | String | Y |
cipher | A constant specifying the cipher to use. Defaults to AES. (see Constants). | Constant | N |
Example
local crypto = require( "crypto" )
local decrypted = crypto.decrypt( "U2FsdGVkX19YaYWtxaJQJZ9LYoIFsCJS7pLF5vjHs+Q9v0c8evHoGWJ1dbYsUOKG", "passphrase" )
print( decrypted ) --> Corona HTML5 Rocks!
crypto.md5
crypto.sha1
crypto.sha224
crypto.sha256
crypto.sha384
crypto.sha512
Does not support md4.
crypto.aes
(default)crypto.des
(triple DES)crypto.rabbit
©2018 C. Byerley (develephant)