Giter Club home page Giter Club logo

defold-crypto's Introduction

Crypto

This is the Crypto module for the Defold game engine and it supports digests and hmac computations for SHA-256, 384 and 512. It is based on this Lua binding and is source-code compatible with the Crypto library of Corona SDK. There is also a basic support for AES128 ECB and CBC encryption algorithms (tiny-AES128-C).

Installation

You can use Crypto in your own project by adding this project as a Defold library dependency. Open your game.project file and in the dependencies field under project add:

https://github.com/sonountaleban/defold-crypto/archive/master.zip

Usage

Here some examples:

local crypto = require("crypto.crypto")

assert(crypto.digest(crypto.sha256, "And so we say goodbye to our beloved pet, Nibbler, who's gone to a place where I, too, hope one day to go. The toilet.") ==
		"3c4ba860b4917a85b075f5e0c8cebe65bd1646d0d5ac3326a974ae965a44a5e1")
		
assert(crypto.hmac(crypto.sha256, "what do ya want for nothing?", "Jefe") ==
	"5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843")
	
assert(crypto.hmac(crypto.sha384, "This is a test!!!", "This is a key??") ==
	"2a0017d73a471f3f6a06000fb51d5df305da6a3e3b384671760aa45be85ffdc15cd6697b4aebafdc6e4b48f85e50d9c8")
	
assert(crypto.hmac(crypto.sha512, "This is a test!!!", "This is a key??") ==
	"01ecc8872d6809c78a98caac7b6d0a26a1373e3a00500cda497ad546d4a4655192f00c1909a1dc419befb3051b17b50c45e1d5f5ad54520c88eda327c1c12f51")

-- input must be a string with length multiple of 16
-- key must be a string with length of 16
result = crypto.encrypt(crypto.aes128ecb, input, key)
result = crypto.decrypt(crypto.aes128ecb, input, key)

-- input must be a string with length multiple of 16
-- key and iv must be strings with length of 16
result = crypto.encrypt(crypto.aes128cbc, input, key, iv)
result = crypto.decrypt(crypto.aes128cbc, input, key, iv)

Limitations

This module is available for all platforms that are currently supported by Native Extensions. Also MD4, MD5, SHA-1 and SHA-224 are not yet implemented.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.