Scrappy Encryption is an encryption helper library for Solar2D.
As with all my plugins it is free to use however if you find it useful, and are able to, I’d appreciate a coffee.
Image Credit: encryption key by ProSymbols from the Noun Project.
There are multiple ways to include the library in your project, the simplest is probably via the plugin, as outlined below, however if you wish you can also access the source code.
build.settings
settings = { plugins = { ["plugin.scrappyEncryption"] = { publisherId = "com.scrappyferret", supportedPlatforms = { iphone = { url="https://plugins.scrappyferret.com/scrappyEncryption/iphone.tgz" }, android = { url="https://plugins.scrappyferret.com/scrappyEncryption/android.tgz" }, macos = false, win32 = false }, }, }, }
main.lua
require( "plugin.scrappyEncryption" ) Scrappy.Encryption:init( params )
If you wish you to access the source code directly it is available on GitLab here.
You can then clone or fork it if you wish, or add the library as a submodule to your project with this command:
git submodule add https://gitlab.com/scrappyferret-libs/scrappy-encryption.git encryption
However you get the source code into your project, you will then need to include it and initiate it.
main.lua
require( "encryption.core" ) Scrappy.Encryption:init( params )
Initialises this Scrappy library.
params ( table ) – Parameters for the initiation, including a cipher suite via ‘type’ property. Possibles can be found here.
Sets the cipher suite for the system to use.
type ( string ) – The suite to set. Possibles can be found here.
Gets the cipher suite that the system is using.
returns – The name of the suite.
Encrypts some data.
data ( string, or table ) – The data to encrypt.
key ( string ) – The encryption key to use.
returns – The encrypted data.
Decrypts some data.
data ( string, or table ) – The data to decrypt.
key ( string ) – The encryption key to use.
returns – The decrypted data.
Destroys this library.
Encrypt some data
-- Initialise the library and set the cipher suite Scrappy.Encryption:init{ cipherSuite = "aes-256-cbc" } -- Encrypt a string local encryptedString = Scrappy.Encryption:encrypt( "Secret message. Shh, don't read.", "passw0rd" ) -- Display the encrypted message print( encryptedString ) -- Create a table local secretData = { purchasedExtraContent = true, } -- Encrypt a table local encryptedTable = Scrappy.Encryption:encrypt( secretData, "passw0rd" ) -- Display the encrypted table print( encryptedTable )
Decrypt some data
local secretMessage = Scrappy.Encryption:decrypt( encryptedString, "passw0rd" ) print( secretMessage ) local secretData = Scrappy.Encryption:decrypt( encryptedTable, "passw0rd" ) print( "Purchased extra content?: " .. secretData.purchasedExtraContent )