Scrappy Encryption

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.

Getting Started

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.



settings =
    plugins =
        ["plugin.scrappyEncryption"] =
            publisherId = "com.scrappyferret",
            supportedPlatforms =
                iphone = { url="" },
                android = { url="" },
                macos = false,
                win32 = false


require( "plugin.scrappyEncryption" )

Scrappy.Encryption:init( params )

Source Code

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 encryption

However you get the source code into your project, you will then need to include it and initiate it.


require( "encryption.core" )

Scrappy.Encryption:init( params )


Scrappy.Device:init( params )

Initialises this Scrappy library.

params ( table ) – Parameters for the initiation, including a cipher suite via ‘type’ property. Possibles can be found here.

Scrappy.Encryption:setCipherSuite( type )

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.

Scrappy.Encryption:encrypt( data, key )

Encrypts some data.

data ( string, or table ) – The data to encrypt.

key ( string ) – The encryption key to use.

returns – The encrypted data.

Scrappy.Encryption:decrypt( data, key )

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 )