--- /dev/null
+package Koha::Encryption;
+
+# Copyright 2022 Koha Development Team
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
+
+use Modern::Perl;
+
+use base qw( Crypt::CBC );
+
+=head1 NAME
+
+Koha::Encryption - Koha class to encrypt or decrypt strings
+
+=head1 SYNOPSIS
+
+ use Koha::Encryption;
+ my $secret = Koha::AuthUtils::generate_salt( 'weak', 16 );
+ my $crypt = Koha::Encryption->new;
+ my $encrypted = $crypt->encrypt_hex($secret);
+ my $decrypted = $crypt->decrypt_hex($encrypted);
+
+ return 1 if $decrypted eq $secret;
+
+It's based on Crypt::CBC
+
+=cut
+
+=head2 METHODS
+
+=head3 new
+
+ my $cipher = Koha::Encryption->new;
+
+ Constructor. Uses encryption_key from koha-conf.xml.
+
+=cut
+
+sub new {
+ my ( $class ) = @_;
+ my $key = C4::Context->config('encryption_key');
+ return $class->SUPER::new(
+ -key => $key,
+ -cipher => 'Cipher::AES'
+ );
+}
+
+1;
--- /dev/null
+use Modern::Perl;
+
+use Test::More tests => 1;
+use Koha::Encryption;
+use t::lib::Mocks;
+
+t::lib::Mocks::mock_config('encryption_key', 'my secret passphrase');
+
+my $string = 'a string to encrypt';
+
+my $crypt = Koha::Encryption->new;
+my $encrypted_string = $crypt->encrypt_hex($string);
+is( $crypt->decrypt_hex($encrypted_string), $string, 'Decrypted to original text' );