File Coverage

blib/lib/App/OATH/Crypt/CBC.pm
Criterion Covered Total %
statement 33 33 100.0
branch n/a
condition n/a
subroutine 9 9 100.0
pod 3 3 100.0
total 45 45 100.0


line stmt bran cond sub pod time code
1             package App::OATH::Crypt::CBC;
2             our $VERSION = '1.20151002'; # VERSION
3              
4 1     1   5 use strict;
  1         2  
  1         29  
5 1     1   6 use warnings;
  1         2  
  1         27  
6 1     1   6 use Convert::Base32;
  1         30  
  1         52  
7 1     1   908 use Crypt::CBC;
  1         5045  
  1         36  
8 1     1   7 use Digest::MD5;
  1         2  
  1         282  
9              
10             sub new {
11 26     26 1 40     my ( $class, $args ) = @_;
12                 my $self = {
13                     'password' => $args->{'password'},
14 26         86         'type' => $args->{'type'},
15                 };
16 26         41     bless $self, $class;
17 26         201     return $self;
18             }
19              
20             sub _get_crypt_object {
21 29     29   53     my ( $self ) = @_;
22 29         52     my $password = $self->{'password'};
23              
24                 my $crypt = Crypt::CBC->new({
25                     'key' => $password,
26 29         196         'cipher' => $self->{'type'},
27                     'salt' => 1,
28                 });
29 29         8083     return $crypt;
30             }
31              
32             sub encrypt {
33 15     15 1 432     my ( $self, $data ) = @_;
34 15         40     my $worker = $self->_get_crypt_object();
35 15         53     my $e = $worker->encrypt( $data );
36 15         18654     $e = encode_base32( $e );
37 15         18315     return $e;
38             }
39              
40             sub decrypt {
41 14     14 1 25     my ( $self, $data ) = @_;
42 14         34     my $worker = $self->_get_crypt_object();
43 14         50     my $e = decode_base32( $data );
44 12         591     my $u = $worker->decrypt($e);
45 12         2309     return $u;
46             }
47              
48             1;
49              
50             __END__
51            
52             =head1 NAME
53            
54             App::OATH::Crypt::CBC - Crypto modules for Simple OATH authenticator
55            
56             =head1 DESCRIPTION
57            
58             Crypto modules for CBC methods, this includes Rijndael and Blowfish
59            
60             =head1 SYNOPSIS
61            
62             Handles encryption and decryption for CBC Rijndael and Blowfish ciphers
63            
64             =head1 METHODS
65            
66             =over
67            
68             =item I<new()>
69            
70             Instantiate a new object
71            
72             =item I<encrypt($data)>
73            
74             Encrypt the given data
75            
76             =item I<decrypt($data)>
77            
78             Decrypt the given data
79            
80             =back
81            
82             =head1 DEPENDENCIES
83            
84             Convert::Base32
85             Crypt::Blowfish
86             Crypt::CBC
87             Crypt::Rijndael
88             Digest::MD5
89             String::Random
90            
91             =head1 AUTHORS
92            
93             Marc Bradshaw E<lt>marc@marcbradshaw.netE<gt>
94            
95             =head1 COPYRIGHT
96            
97             Copyright 2015
98            
99             This library is free software; you may redistribute it and/or
100             modify it under the same terms as Perl itself.
101            
102