App-OATH

 view release on metacpan or  search on metacpan

lib/App/OATH/Crypt/CBC.pm  view on Meta::CPAN

package App::OATH::Crypt::CBC;
our $VERSION = '1.20260324'; # VERSION

use strict;
use warnings;
use Convert::Base32;
use Crypt::CBC;
use Digest::MD5;

sub new {
    my ( $class, $args ) = @_;
    my $self = {
        'password' => $args->{'password'},
        'type'     => $args->{'type'},
    };
    bless $self, $class;
    return $self;
}

sub _get_crypt_object {
    my ( $self ) = @_;
    my $password = $self->{'password'};

    my $crypt = Crypt::CBC->new({
        'key'    => $password,
        'cipher' => $self->{'type'},
        'salt'   => 1,
    });
    return $crypt;
}

sub encrypt {
    my ( $self, $data ) = @_;
    my $worker = $self->_get_crypt_object();
    my $e = $worker->encrypt( $data );
    $e = encode_base32( $e );
    return $e;
}

sub decrypt {
    my ( $self, $data ) = @_;
    my $worker = $self->_get_crypt_object();
    my $e = decode_base32( $data );
    my $u = $worker->decrypt($e);
    return $u;
}

1;

__END__

=head1 NAME

App::OATH::Crypt::CBC - Crypto modules for Simple OATH authenticator

=head1 DESCRIPTION

Crypto modules for CBC methods, this includes Rijndael and Blowfish

=head1 SYNOPSIS

Handles encryption and decryption for CBC Rijndael and Blowfish ciphers



( run in 1.938 second using v1.01-cache-2.11-cpan-39bf76dae61 )