line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# crypto::aes Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::Crypto::Aes; |
7
|
1
|
|
|
1
|
|
572
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
31
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
6
|
use base qw(Metabrik); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
563
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub brik_properties { |
13
|
|
|
|
|
|
|
return { |
14
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
15
|
|
|
|
|
|
|
tags => [ qw(unstable) ], |
16
|
|
|
|
|
|
|
author => 'GomoR ', |
17
|
|
|
|
|
|
|
license => 'http://opensource.org/licenses/BSD-3-Clause', |
18
|
|
|
|
|
|
|
commands => { |
19
|
|
|
|
|
|
|
encrypt => [ qw($data) ], |
20
|
|
|
|
|
|
|
decrypt => [ qw($data) ], |
21
|
|
|
|
|
|
|
}, |
22
|
|
|
|
|
|
|
#require_modules => { |
23
|
|
|
|
|
|
|
#'Crypt::CBC' => [ ], |
24
|
|
|
|
|
|
|
#'Crypt::OpenSSL::AES' => [ ], |
25
|
|
|
|
|
|
|
#}, |
26
|
|
|
|
|
|
|
require_binaries => { |
27
|
|
|
|
|
|
|
'openssl' => [ ], |
28
|
|
|
|
|
|
|
}, |
29
|
|
|
|
|
|
|
}; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub encrypt { |
33
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
34
|
0
|
|
|
|
|
|
my ($data) = @_; |
35
|
|
|
|
|
|
|
|
36
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('encrypt', $data) or return; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
#my $key = 'key'; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
#my $cipher = Crypt::CBC->new( |
41
|
|
|
|
|
|
|
#-key => $key, |
42
|
|
|
|
|
|
|
#-cipher => 'Crypt::OpenSSL::AES', |
43
|
|
|
|
|
|
|
#) or return $self->log->error("cipher: $!"); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
#my $crypted = $cipher->encrypt_hex($data); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# Will only return hex encoded data |
48
|
0
|
|
|
|
|
|
my $crypted = `echo "$data" | openssl enc -e -a -aes-128-cbc`; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
return $crypted; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub decrypt { |
54
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
55
|
0
|
|
|
|
|
|
my ($data) = @_; |
56
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('decrypt', $data) or return; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
#my $key = 'key'; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
#my $cipher = Crypt::CBC->new( |
62
|
|
|
|
|
|
|
#-key => $key, |
63
|
|
|
|
|
|
|
#-cipher => 'Crypt::OpenSSL::AES', |
64
|
|
|
|
|
|
|
#) or return $self->log->error("cipher: $!"); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
#my $decrypted = $cipher->decrypt_hex($data); |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
$self->log->debug("echo \"$data\" | openssl enc -d -a -aes-128-cbc"); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# Will only return hex decoded data |
71
|
0
|
|
|
|
|
|
my $decrypted = `echo "$data" | openssl enc -d -a -aes-128-cbc`; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
return $decrypted; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
__END__ |