View | Details | Raw Unified | Return to bug 28998
Collapse All | Expand All

(-)a/Koha/Encryption.pm (+57 lines)
Line 0 Link Here
1
package Koha::Encryption;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use base qw( Crypt::CBC );
21
22
=head1 NAME
23
24
Koha::Encryption - Koha class to encrypt or decrypt strings
25
26
=head1 SYNOPSIS
27
28
use Koha::Encryption;
29
my $secret = Koha::AuthUtils::generate_salt( 'weak', 16 );
30
my $crypt = Koha::Encryption->new;
31
my $encrypted = $crypt->encrypt_hex($secret);
32
my $decrypted = crypt->decrypt_hex($encrypted);
33
34
It's based on Crypt::CBC
35
36
=cut
37
38
=head2 METHODS
39
40
=head3 new
41
42
    my $cipher = Koha::Encryption->new;
43
44
    Constructor. Uses encryption_key from koha-conf.xml.
45
46
=cut
47
48
sub new {
49
    my ( $class ) = @_;
50
    my $key = C4::Context->config('encryption_key');
51
    return $class->SUPER::new(
52
        -key    => $key,
53
        -cipher => 'Cipher::AES'
54
    );
55
}
56
57
1;
(-)a/t/db_dependent/Koha/Encryption.t (-1 / +13 lines)
Line 0 Link Here
0
- 
1
use Modern::Perl;
2
3
use Test::More tests => 1;
4
use Koha::Encryption;
5
use t::lib::Mocks;
6
7
t::lib::Mocks::mock_config('encryption_key', 'my secret passphrase');
8
9
my $string = 'a string to encrypt';
10
11
my $crypt = Koha::Encryption->new;
12
my $encrypted_string = $crypt->encrypt_hex($string);
13
is( $crypt->decrypt_hex($encrypted_string), $string, 'Decrypted to original text' );

Return to bug 28998