1 package Koha::Encryption;
3 # Copyright 2022 Koha Development Team
5 # This file is part of Koha.
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.
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.
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>.
22 use base qw( Crypt::CBC );
29 Koha::Encryption - Koha class to encrypt or decrypt strings
34 my $secret = Koha::AuthUtils::generate_salt( 'weak', 16 );
35 my $crypt = Koha::Encryption->new;
36 my $encrypted = $crypt->encrypt_hex($secret);
37 my $decrypted = $crypt->decrypt_hex($encrypted);
39 return 1 if $decrypted eq $secret;
41 It's based on Crypt::CBC
49 my $cipher = Koha::Encryption->new;
51 Constructor. Uses encryption_key from koha-conf.xml.
57 my $key = C4::Context->config('encryption_key');
59 Koha::Exceptions::MissingParameter->throw('No encryption_key in koha-conf.xml');
61 return $class->SUPER::new(
63 -cipher => 'Cipher::AES'