Egg::Plugin::Crypt::CBC - Crypt::CBC for Egg Plugin.


Egg-Plugin-Crypt-CBC documentation Contained in the Egg-Plugin-Crypt-CBC distribution.

Index


Code Index:

NAME

Top

Egg::Plugin::Crypt::CBC - Crypt::CBC for Egg Plugin.

SYNOPSIS

Top

  use Egg qw/ Crypt::CBC /;

  __PACKAGE__->egg_startup(
   .....
   ...

   plugin_crypt_cbc => {
     cipher=> 'Blowfish',
     key   => 'uniqueid',
     ...
     },

   );

  # The text is encrypted.
  my $crypt= $e->cbc->encode($text);

  # The code end text is decrypted.
  my $plain= $e->cbc->decode($crypt);

  # The cbc object is acquired in an arbitrary option.
  my $cbc= $e->cbc( cipher => 'DES' );

DESCRIPTION

Top

It is a plugin to use the code and decoding by Crypt::CBC.

CONFIGURATION

Top

HASH is defined in 'plugin_crypt_cbc' key and it sets it.

The setting is an option to pass everything to Crypt::CBC.

Please refer to the document of Crypt::CBC for details.

cipher

The exception is generated in case of undefined.

key

The exception is generated in case of undefined.

iv

'$KJh#(}q' is provisionally defined in case of undefined.

Please define it.

padding

Default is 'standard'.

prepend_iv

Default is 0.

regenerate_key

Default is 1.

METHODS

Top

cbc ( [OPTION_HASH] )

The handler object of this plugin is returned.

It turns by using the same object when the object is generated once usually. When OPTION_HASH is given, it tries to generate the object newly.

HANDLER METHODS

Top

The handler object has succeeded to Crypt::CBC.

new

Top

Constructor.

encode ( [PLAIN_TEXT] )

Top

After PLAIN_TEXT is encrypted, the Base64 encode text is returned.

  my $crypt_text= $e->cbc->encode( 'plain text' );

decode ( [CRYPT_TEXT] )

Top

The text encrypted by 'encode' method is made to the compound and returned.

  my $plain_text= $e->cbc->decode( 'crypt text' );

SEE ALSO

Top

Egg::Release, Crypt::CBC,

AUTHOR

Top

Masatoshi Mizuno <lushe&64;cpan.org>

COPYRIGHT AND LICENSE

Top


Egg-Plugin-Crypt-CBC documentation Contained in the Egg-Plugin-Crypt-CBC distribution.

package Egg::Plugin::Crypt::CBC;
#
# Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt>
#
# $Id: CBC.pm 318 2008-04-17 12:17:01Z lushe $
#
use strict;
use warnings;

our $VERSION = '3.01';

sub _setup {
	my($e)= @_;
	my $conf= $e->config->{plugin_crypt_cbc} ||= {};

	$conf->{cipher}  || die q{ Please setup 'plugin_crypt_cbc->{cipher}'. };
	$conf->{key}     || die q{ Please setup 'plugin_crypt_cbc->{key}'. };
	$conf->{iv}      ||= '$KJh#(}q';
	$conf->{padding} ||= 'standard';
	$conf->{prepend_iv}= 0 unless exists($conf->{prepend_iv});
	$conf->{regenerate_key}= 1 unless exists($conf->{regenerate_key});

	$e->next::method;
}
sub cbc {
	my $e= shift;
	@_ ? ($e->{crypt_cbc}= Egg::Plugin::Crypt::CBC::handler->new($e, @_))
	   : ($e->{crypt_cbc} ||= Egg::Plugin::Crypt::CBC::handler->new($e))
}

package Egg::Plugin::Crypt::CBC::handler;
use strict;
use warnings;
use MIME::Base64;
use base qw/Crypt::CBC/;

sub new {
	my($class, $e)= splice @_, 0, 2;
	my %option= (
	  %{$e->config->{plugin_crypt_cbc}},
	  %{ $_[1] ? {@_}: ($_[0] || {}) },
	  );
	$class->SUPER::new(\%option);
}
sub encode {
	my $self = shift;
	my $plain= shift || return "";
	my $crypt= encode_base64( $self->encrypt($plain) );
	$crypt=~tr/\r\n\t//d;
	$crypt || "";
}
sub decode {
	my $self = shift;
	my $crypt= shift || return "";
	$self->decrypt( decode_base64($crypt) ) || "";
}

1;

__END__