NAME

Mojolicious::Plugin::Crypto - Provide interface to symmetric cipher algorithms using cipher-block chaining

AES, Blowfish, DES, 3DES, IDEA... and more

SYNOPSIS

use Mojolicious::Plugin::Crypt;

my $fix_key = 'secretpassphrase';
my $plain = "NemuxMojoCrypt";

#... 
# You can leave key value empty and it will generate a new key for you

my ($crypted, $key)  = $t->app->crypt_aes($plain, $fix_key);

#... [ store this crypted data where do you want ... ]

# and decrypt it
my $clean =  $t->app->decrypt_aes($crypted, $key);
 

DESCRIPTION

You can use this plugin in order to encrypt and decrypt using one of these algorithms:

AES (aka Rijndael) Blowfish DES DES_EDE (aka Triple-DES, 3DES) IDEA TWOFISH XTEA ANUBIS CAMELLIA KASUMI KHAZAD NOEKEON MULTI2 RC2 RC5 RC6

USAGE

crypt_[ALGO_NAME]()

call function crypt_ followed by the algo name in lowercase. For example crypt_aes("My Plain Test", "ThisIsMySecretKey")
ann array will be the return value ('securedata', 'keyused'). 

decrypt_[ALGO_NAME]()

The same thing for decryption decrypt_ followed by the algo name in lowercase
Ex.: decrypt_aes("MyCryptedValue","ThisIsMySecretKey") it will return just a scalar value with the plain text. That's all.

crypt_des_ede(),crypt_3des(),crypt_tripple_des()...

methods list (just to write something)

crypt_aes() crypt_blowfish() crypt_des() crypt_3des() [|| crypt_des_ede() || crypt_triple_des()] crypt_idea() crypt_twofish() crypt_xtea(); crypt_anubis(); crypt_camellia(); crypt_kasumi(); crypt_khazad(); crypt_noekeon(); crypt_multi2(); crypt_rc2(); crypt_rc5(); crypt_rc6();

and the same for decrypt functions (please make the effort to put "de" in front of "crypt")

Retrurn value is an array to make easy a super cryptO call like this... :)

Crypt::

($crypted, $key) = app->crypt_xtea(app->crypt_twofish(app->crypt_idea(app->crypt_3des(app->crypt_blowfish(app->crypt_aes($super_plain,$super_secret))))));

Decrypt::

($plain, $key) = app->decrypt_aes(app->decrypt_blowfish(app->decrypt_3des(app->decrypt_idea(app->decrypt_twofish(app->decrypt_xtea($crypted,$super_secret))))));

Dummy example using Mojolicious::Lite

You can test in this way

perl mymojoapp.pl /aes/enc?data=nemux
perl mymojoapp.pl /aes/dec?data=53616c7465645f5f6355829a809369eee5dfb9489eaee7e190b67d15d2e35ce8

perl mymojoapp.pl /blowfish/enc?data=nemux
perl mymojoapp.pl /blowfish/dec?data=53616c7465645f5f16d8c8aa479121d039b04703083a9391

#!/usr/bin/env perl

### All glory to the Hypnotoad

use Mojolicious::Lite;
plugin 'Crypto';

my $bigsecret = "MyNameisMarcoRomano";

get '/aes/enc' => sub {
  my $self = shift;
  my $data = $self->param('data');
  my ($securedata) = $self->crypt_aes($data, $bigsecret);
  $self->render(text => $securedata);
};

get '/aes/dec' => sub {
  my $self = shift;
  my $data = $self->param('data');
  my ($plaintext) = $self->decrypt_aes($data, $bigsecret);
  $self->render(text => $plaintext);
};

get '/blowfish/enc' => sub {
  my $self = shift;
  my $data = $self->param('data');
  my ($securedata) = $self->crypt_blowfish($data, $bigsecret);
  $self->render(text => $securedata);
};

get '/blowfish/dec' => sub {
  my $self = shift;
  my $data = $self->param('data');
  my ($plaintext) = $self->decrypt_blowfish($data, $bigsecret);
  $self->render(text => $plaintext);
};

app->start;

BUGS

No bugs for now...

SUPPORT

Write me if you need some help and feel free to improve it. You can find me on irc freenode sometimes.

AUTHOR

Marco Romano
CPAN ID: NEMUX
Mojolicious CryptO Plugin
nemux@cpan.org
http://search.cpan.org/~nemux/

COPYRIGHT

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.

SEE ALSO

perl(1).