Bugzilla – Attachment 133523 Details for
Bug 28998
Encrypt borrowers.secret
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 28998: Introduce Koha::Encryption
Bug-28998-Introduce-KohaEncryption.patch (text/plain), 2.82 KB, created by
Marcel de Rooy
on 2022-04-21 08:41:12 UTC
(
hide
)
Description:
Bug 28998: Introduce Koha::Encryption
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2022-04-21 08:41:12 UTC
Size:
2.82 KB
patch
obsolete
>From 7c475ffd8c7292c0a41db817f0bca2df3a459eac Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Fri, 10 Sep 2021 11:27:33 +0200 >Subject: [PATCH] Bug 28998: Introduce Koha::Encryption >Content-Type: text/plain; charset=utf-8 > >Test plan: >Run t/db_dependent/Koha/Encryption.t > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >[AMENDED] Added copyright line to module. >--- > Koha/Encryption.pm | 59 ++++++++++++++++++++++++++++++++ > t/db_dependent/Koha/Encryption.t | 13 +++++++ > 2 files changed, 72 insertions(+) > create mode 100644 Koha/Encryption.pm > create mode 100755 t/db_dependent/Koha/Encryption.t > >diff --git a/Koha/Encryption.pm b/Koha/Encryption.pm >new file mode 100644 >index 0000000000..fc1375a3d1 >--- /dev/null >+++ b/Koha/Encryption.pm >@@ -0,0 +1,59 @@ >+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); >+ >+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; >diff --git a/t/db_dependent/Koha/Encryption.t b/t/db_dependent/Koha/Encryption.t >new file mode 100755 >index 0000000000..52373ffaf7 >--- /dev/null >+++ b/t/db_dependent/Koha/Encryption.t >@@ -0,0 +1,13 @@ >+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' ); >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 28998
:
124772
|
124773
|
124774
|
133291
|
133317
|
133318
|
133319
|
133320
|
133321
|
133322
|
133323
|
133523
|
133524
|
133525
|
133526
|
133527
|
133528
|
133529
|
133580
|
133581
|
133582
|
133583
|
133584
|
133585
|
133586
|
133588
|
133619
|
133620
|
133621
|
133622
|
133623
|
133624
|
133625
|
133626
|
133627
|
133628
|
133629
|
133631
|
133632
|
133633
|
133634
|
133635
|
133636
|
133637
|
133638
|
133639
|
133640
|
133641
|
133642
|
133645
|
133646
|
133647
|
133648
|
133649
|
133650
|
133651
|
133652
|
133653
|
133654
|
133655
|
134636
|
134637
|
134671