line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::RNCryptor; |
2
|
2
|
|
|
2
|
|
15299
|
use 5.008001; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
61
|
|
3
|
2
|
|
|
2
|
|
7
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
52
|
|
4
|
2
|
|
|
2
|
|
14
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
46
|
|
5
|
2
|
|
|
2
|
|
8
|
use Carp; |
|
2
|
|
|
|
|
0
|
|
|
2
|
|
|
|
|
537
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $DefaultRNCryptorVersion = '3'; |
10
|
|
|
|
|
|
|
our @SupportedRNCryptorVersions = qw(3); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
11
|
|
|
11
|
1
|
140620
|
my ($class, %opts) = @_; |
14
|
11
|
|
33
|
|
|
76
|
$opts{version} ||= $DefaultRNCryptorVersion; |
15
|
11
|
|
|
|
|
29
|
foreach my $v (@SupportedRNCryptorVersions) { |
16
|
11
|
50
|
|
|
|
38
|
if ($opts{version} eq $v) { |
17
|
11
|
|
|
|
|
24
|
my $Class = "Crypt::RNCryptor::V${v}"; |
18
|
11
|
|
|
|
|
567
|
eval "require $Class"; |
19
|
11
|
|
|
|
|
77
|
return $Class->new(%opts); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
} |
22
|
0
|
|
|
|
|
|
my $v = $opts{version}; |
23
|
0
|
|
|
|
|
|
confess "RNCryptor v$v is not supported."; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub encrypt { |
27
|
0
|
|
|
0
|
1
|
|
confess 'This is an abstract method.'; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub decrypt { |
31
|
0
|
|
|
0
|
1
|
|
confess 'This is an abstract method.'; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
1; |
35
|
|
|
|
|
|
|
__END__ |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=encoding utf-8 |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 NAME |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Crypt::RNCryptor - Perl implementation of L<RNCryptor|https://github.com/RNCryptor/RNCryptor> |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 SYNOPSIS |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
use Crypt::RNCryptor; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# generate password-based encryptor |
48
|
|
|
|
|
|
|
$cryptor = Crypt::RNCryptor->new( |
49
|
|
|
|
|
|
|
password => 'secret password', |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# generate key-based encryptor |
53
|
|
|
|
|
|
|
$cryptor = Crypt::RNCryptor->new( |
54
|
|
|
|
|
|
|
encryption_key => '', |
55
|
|
|
|
|
|
|
hmac_key => '', |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# encrypt |
59
|
|
|
|
|
|
|
$ciphertext = $cryptor->encrypt('plaintext'); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# decrypt |
62
|
|
|
|
|
|
|
$plaintext = $cryptor->decrypt($ciphertext); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 DESCRIPTION |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Crypt::RNCryptor is a Perl implementation of RNCryptor, |
67
|
|
|
|
|
|
|
which is one of data format for AES-256 (CBC mode) encryption. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Crypt::RNCryptor class is the base of Crypt::RNCryptor::V* class |
70
|
|
|
|
|
|
|
and declare some abstract methods. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 METHODS |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head2 CLASS METHODS |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=over 4 |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=item my $cryptor = Crypt::RNCryptor->new(%opts); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Create a cryptor instance. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
%opts = ( |
83
|
|
|
|
|
|
|
# RNCryptor version. Currently support only version 3) |
84
|
|
|
|
|
|
|
version => $Crypt::RNCryptor::DefaultRNCryptorVersion, |
85
|
|
|
|
|
|
|
# See Crypt::RNCryptor::V* |
86
|
|
|
|
|
|
|
%version_dependent_opts |
87
|
|
|
|
|
|
|
); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=back |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 INSTANCE METHODS |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=over 4 |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=item $ciphertext = $cryptor->encrypt($plaintext, %version_dependent_opts) |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Encrypt plaintext with options. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=item $plaintext = $cryptor->decrypt($ciphertext, %version_dependent_opts) |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Decrypt ciphertext with options. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=back |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 MODULE VARIABLES |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=over 4 |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item $Crypt::RNCryptor::DefaultRNCryptorVersion = '3' |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Default RNCryptor version. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=item @Crypt::RNCryptor::DefaultRNCryptorVersion |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
List of supporting RNCryptor versions. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=back |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 LICENSE |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Copyright (C) Shintaro Seki. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
124
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 AUTHOR |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Shintaro Seki E<lt>s2pch.luck@gmail.comE<gt> |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |