NAME

Mojolicious::Plugin::Crypto - Provide interface to some cryptographic stuff.

SYNOPSIS

use Mojolicious::Plugin::Crypt;

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

#### Symmetric Functions
# 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);
 
### Hash

### From string/buffer
my $digest_hex = $t->app->sha256_hex("Take this content");
### From filehandle
my $digest_raw = $t->app->sha256_file(*FILEHANDLE);
### From File
$digest_hex    = $t->app->sha256_file_hex('filename.txt');

### base64
my $digest_b64  = $t->app->sha256_b64('data string');
my $digest_b64u = $t->app->sha256_b64u('data string');

DESCRIPTION

Support some cryptographic functions like symmetric cipher algorithms using cipher-block chaining. AES, Blowfish, DES, 3DES, IDEA... and more, see below. Hash/Digest Functions - SHA*, MD*, Whirlpool, CHAES, RIPEMD*, Tiger192

Symmetric algorithms supported

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

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

USAGE

crypt_[ALGO_NAME]()

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

decrypt_[ALGO_NAME]()

The same thing for decryption decrypt_ followed by the algorithms name in lowercase
Ex.: decrypt_aes("MyCryptedValue","ThisIsMySecretKey") it will return an array with two values: 
the first one is the clear text decrypted and the last one the key used. That's all.

methods list

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_[name]")

3DES: Multiple names, same result

1 crypt_des_ede() =item 2 crypt_3des(), =item 3 crypt_tripple_des()

nested calls

  • 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))))));

Hash/Digest Functions

Use this plugin in order to calculate digest through this algorithms:

  • SHA1 =item * SHA224 =item * SHA256 =item * SHA384 =item * SHA512 =item * MD2 =item * MD4 =item * MD5 =item * Whirlpool =item * CHAES =item * RIPEMD128 =item * RIPEMD160 =item * RIPEMD256 =item * RIPEMD320 =item * Tiger192

USAGE

[ALGO_NAME]()

Example: app->sha256();

[ALGO_NAME]_hex()

Example: app->sha256_hex();

[ALGO_NAME]_b64()

Example: app->sha256_b64();

[ALGO_NAME]_b64u()

Example: app->sha256_b64u();

[ALGO_NAME]_file([FILENAME|FILEHANDLE])

Example: app->sha256_file();

[ALGO_NAME]_file_hex([FILENAME|FILEHANDLE])

Example: app->sha256_file_hex();

[ALGO_NAME]_file_b64([FILENAME|FILEHANDLE])

Example: app->sha256_file_b64();

[ALGO_NAME]_file_b64u([FILENAME|FILEHANDLE])

Example: app->sha256_file_b64u();

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

  use Mojolicious::Lite;
  plugin 'Crypto';

  my $bigsecret = "MyNameisMarcoRomano";

  get '/digest/sha256' => sub {
    my $self = shift;
    my $data = $self->param('data');
    my $hex_digest = $self->sha256_hex($data);
    $self->render(text => $hex_digest);
  };

  get '/digest/md5' => sub {
    my $self = shift;
    my $data = $self->param('data');
    my ($hex_digest) = $self->md5_hex($data);
    $self->render(text => $hex_digest);
  };

  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

TODO

  • Random numbers generator =item * Asymmetric algorithms =item * Avoiding to load all modules but just what you need

SUPPORT

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

Github: http://git.io/lQl5cA

AUTHOR

Marco Romano
CPAN ID: NEMUX
Mojolicious CryptO Plugin

nemux@cpan.org - @nemux_ 

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).

5 POD Errors

The following errors were encountered while parsing the POD:

Around line 200:

You forgot a '=back' before '=head1'

Around line 242:

You forgot a '=back' before '=head2'

Around line 252:

'=item' outside of any '=over'

Around line 280:

You forgot a '=back' before '=head1'

Around line 386:

You forgot a '=back' before '=head1'