| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Egg::Plugin::Crypt::CBC; |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt> |
|
4
|
|
|
|
|
|
|
# |
|
5
|
|
|
|
|
|
|
# $Id: CBC.pm 318 2008-04-17 12:17:01Z lushe $ |
|
6
|
|
|
|
|
|
|
# |
|
7
|
2
|
|
|
2
|
|
620
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
74
|
|
|
8
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
422
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '3.01'; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub _setup { |
|
13
|
0
|
|
|
0
|
|
|
my($e)= @_; |
|
14
|
0
|
|
0
|
|
|
|
my $conf= $e->config->{plugin_crypt_cbc} ||= {}; |
|
15
|
|
|
|
|
|
|
|
|
16
|
0
|
0
|
|
|
|
|
$conf->{cipher} || die q{ Please setup 'plugin_crypt_cbc->{cipher}'. }; |
|
17
|
0
|
0
|
|
|
|
|
$conf->{key} || die q{ Please setup 'plugin_crypt_cbc->{key}'. }; |
|
18
|
0
|
|
0
|
|
|
|
$conf->{iv} ||= '$KJh#(}q'; |
|
19
|
0
|
|
0
|
|
|
|
$conf->{padding} ||= 'standard'; |
|
20
|
0
|
0
|
|
|
|
|
$conf->{prepend_iv}= 0 unless exists($conf->{prepend_iv}); |
|
21
|
0
|
0
|
|
|
|
|
$conf->{regenerate_key}= 1 unless exists($conf->{regenerate_key}); |
|
22
|
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
$e->next::method; |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
sub cbc { |
|
26
|
0
|
|
|
0
|
1
|
|
my $e= shift; |
|
27
|
0
|
0
|
0
|
|
|
|
@_ ? ($e->{crypt_cbc}= Egg::Plugin::Crypt::CBC::handler->new($e, @_)) |
|
28
|
|
|
|
|
|
|
: ($e->{crypt_cbc} ||= Egg::Plugin::Crypt::CBC::handler->new($e)) |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
package Egg::Plugin::Crypt::CBC::handler; |
|
32
|
2
|
|
|
2
|
|
20
|
use strict; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
44
|
|
|
33
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
62
|
|
|
34
|
2
|
|
|
2
|
|
1787
|
use MIME::Base64; |
|
|
2
|
|
|
|
|
1767
|
|
|
|
2
|
|
|
|
|
168
|
|
|
35
|
2
|
|
|
2
|
|
15
|
use base qw/Crypt::CBC/; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
2195
|
|
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub new { |
|
38
|
0
|
|
|
0
|
|
|
my($class, $e)= splice @_, 0, 2; |
|
39
|
0
|
|
|
|
|
|
my %option= ( |
|
40
|
0
|
0
|
0
|
|
|
|
%{$e->config->{plugin_crypt_cbc}}, |
|
41
|
0
|
|
|
|
|
|
%{ $_[1] ? {@_}: ($_[0] || {}) }, |
|
42
|
|
|
|
|
|
|
); |
|
43
|
0
|
|
|
|
|
|
$class->SUPER::new(\%option); |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
sub encode { |
|
46
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
47
|
0
|
|
0
|
|
|
|
my $plain= shift || return ""; |
|
48
|
0
|
|
|
|
|
|
my $crypt= encode_base64( $self->encrypt($plain) ); |
|
49
|
0
|
|
|
|
|
|
$crypt=~tr/\r\n\t//d; |
|
50
|
0
|
0
|
|
|
|
|
$crypt || ""; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
sub decode { |
|
53
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
54
|
0
|
|
0
|
|
|
|
my $crypt= shift || return ""; |
|
55
|
0
|
0
|
|
|
|
|
$self->decrypt( decode_base64($crypt) ) || ""; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__END__ |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 NAME |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Egg::Plugin::Crypt::CBC - Crypt::CBC for Egg Plugin. |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
use Egg qw/ Crypt::CBC /; |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
__PACKAGE__->egg_startup( |
|
71
|
|
|
|
|
|
|
..... |
|
72
|
|
|
|
|
|
|
... |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
plugin_crypt_cbc => { |
|
75
|
|
|
|
|
|
|
cipher=> 'Blowfish', |
|
76
|
|
|
|
|
|
|
key => 'uniqueid', |
|
77
|
|
|
|
|
|
|
... |
|
78
|
|
|
|
|
|
|
}, |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
); |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# The text is encrypted. |
|
83
|
|
|
|
|
|
|
my $crypt= $e->cbc->encode($text); |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# The code end text is decrypted. |
|
86
|
|
|
|
|
|
|
my $plain= $e->cbc->decode($crypt); |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# The cbc object is acquired in an arbitrary option. |
|
89
|
|
|
|
|
|
|
my $cbc= $e->cbc( cipher => 'DES' ); |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
It is a plugin to use the code and decoding by L<Crypt::CBC>. |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 CONFIGURATION |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
HASH is defined in 'plugin_crypt_cbc' key and it sets it. |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
The setting is an option to pass everything to L<Crypt::CBC>. |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Please refer to the document of L<Crypt::CBC> for details. |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 cipher |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
The exception is generated in case of undefined. |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head2 key |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
The exception is generated in case of undefined. |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head2 iv |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
'$KJh#(}q' is provisionally defined in case of undefined. |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Please define it. |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 padding |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Default is 'standard'. |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head2 prepend_iv |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Default is 0. |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head2 regenerate_key |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Default is 1. |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 METHODS |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head2 cbc ( [OPTION_HASH] ) |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
The handler object of this plugin is returned. |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
It turns by using the same object when the object is generated once usually. |
|
136
|
|
|
|
|
|
|
When OPTION_HASH is given, it tries to generate the object newly. |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 HANDLER METHODS |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
The handler object has succeeded to L<Crypt::CBC>. |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 new |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Constructor. |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 encode ( [PLAIN_TEXT] ) |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
After PLAIN_TEXT is encrypted, the Base64 encode text is returned. |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
my $crypt_text= $e->cbc->encode( 'plain text' ); |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 decode ( [CRYPT_TEXT] ) |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
The text encrypted by 'encode' method is made to the compound and returned. |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
my $plain_text= $e->cbc->decode( 'crypt text' ); |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
L<Egg::Release>, |
|
161
|
|
|
|
|
|
|
L<Crypt::CBC>, |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 AUTHOR |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt> |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Copyright (C) 2008 Bee Flag, Corp. E<lt>L<http://egg.bomcity.com/>E<gt>, All Rights Reserved. |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
172
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.6 or, |
|
173
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=cut |
|
176
|
|
|
|
|
|
|
|