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