Code Monkey home page Code Monkey logo

dcrypto's Introduction

dcrypto - Dart crypto

Simple extendable crypto package written in Dart

Structure

There is the Crypto wrapper responsible for data normalization. There are types of data how it is passed to the handler and it creates the right format. The CryptoDescriptor define the main functionalities of the extensions.

Usage (AES-CBC-128)

import 'package:dcrypto/dcrypto.dart';

// Create a new Crypto instance and passing the extension to it.
// AES_CBC_128 is the extension and requires an initialization vector.
var c = Crypto(AES_CBC_128('2271z4734hxepwb6'));

// The default values for key and plaintext types are base64
var key = 'eGVxMW04aTk1OXIzYndndQ=='; // xeq1m8i959r3bwgu
var plaintext = 'bTUxdWFxZGcyNjNhNW53Mw=='; // m51uaqdg263a5nw3

// Pass the plaintext and key to the encrypt endpoint
// Returns a base64 encoded ciphertext (can't be changed)
var ciphertext = c.encrypt(plaintext, key);

// ...

// Pass the ciphertext to the decrypt along with the key
// Returns the decrypted value as base64 encoded
var decrypted = c.decrypt(ciphertext, key);

Change input types

import 'package:dcrypto/dcrypto.dart';

var c = Crypto(AES_CBC_128('2271z4734hxepwb6'));
c.keyType = TextType.pure; // Change the key type to pure (simple string)
c.plaintextType = TextType.pure; // Change the plaintext type to pure (simple string)

var key = 'xeq1m8i959r3bwgu';
var plaintext = 'm51uaqdg263a5nw3';

// NOTE: Returns a base64 encoded ciphertext (can't be changed)
var ciphertext = c.encrypt(plaintext, key);

// ...

// Returns the decrypted value as base64 encoded because it's change back
c.plaintextType = TextType.base64;
var decrypted = c.decrypt(ciphertext, key);

Writing extensions

Extensions must implement the CryptoDescriptor to be accepted. All of the inputs arrives as pure TextType except the ciphertext. Ciphertext always based on the implementation, but it's suggested to accept the same format for decryption as the encrypt returned it.

dcrypto's People

Contributors

jkirtyan avatar pumpkinseed avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

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.