Skip to content

Commit f6fb60d

Browse files
authored
Merge pull request codeigniter4#7273 from kenjis/fix-Encryption-CI3-compat
fix: Encryption CI3 compatibility
2 parents 1970133 + 24438f5 commit f6fb60d

9 files changed

Lines changed: 127 additions & 12 deletions

File tree

app/Config/Encryption.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,13 @@ class Encryption extends BaseConfig
8080
* Set to 'authentication' for CI3 Encryption compatibility.
8181
*/
8282
public string $authKeyInfo = '';
83+
84+
/**
85+
* Cipher to use.
86+
* This setting is only used by OpenSSLHandler.
87+
*
88+
* Set to 'AES-128-CBC' to decrypt encrypted data that encrypted
89+
* by CI3 Encryption default configuration.
90+
*/
91+
public string $cipher = 'AES-256-CTR';
8392
}

tests/system/Encryption/EncryptionTest.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,25 @@ public function testMagicGetMissing()
151151
$this->assertNull($this->encryption->bogus);
152152
}
153153

154-
public function testDecryptEncryptedDataByCI3()
154+
public function testDecryptEncryptedDataByCI3AES128CBC()
155+
{
156+
$config = new EncryptionConfig();
157+
$config->driver = 'OpenSSL';
158+
$config->key = hex2bin('64c70b0b8d45b80b9eba60b8b3c8a34d0193223d20fea46f8644b848bf7ce67f');
159+
$config->cipher = 'AES-128-CBC'; // CI3's default config
160+
$config->rawData = false;
161+
$config->encryptKeyInfo = 'encryption';
162+
$config->authKeyInfo = 'authentication';
163+
$encrypter = Services::encrypter($config, false);
164+
165+
$encrypted = '211c55b9d1948187557bff88c1e77e0f6b965e3711d477d97fb0b60907a7336028714dbb8dfe90598039e9bc7147b54e552d739b378cd864fb91dde9ad6d4ffalIvVxFDDLTPBYGaHLNDzUSJExBKbQJ0NW27KDaR83bYqz8MDz/mXXpE+HHdaWjEE';
166+
$decrypted = $encrypter->decrypt($encrypted);
167+
168+
$expected = 'This is a plain-text message.';
169+
$this->assertSame($expected, $decrypted);
170+
}
171+
172+
public function testDecryptEncryptedDataByCI3AES256CTR()
155173
{
156174
$config = new EncryptionConfig();
157175
$config->driver = 'OpenSSL';

user_guide_src/source/changelogs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ See all the changes.
1212
.. toctree::
1313
:titlesonly:
1414

15+
v4.3.3
1516
v4.3.2
1617
v4.3.1
1718
v4.3.0
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Version 4.3.3
2+
#################
3+
4+
Release Date: Unreleased
5+
6+
**4.3.3 release of CodeIgniter4**
7+
8+
.. contents::
9+
:local:
10+
:depth: 3
11+
12+
BREAKING
13+
********
14+
15+
Message Changes
16+
***************
17+
18+
Changes
19+
*******
20+
21+
Deprecations
22+
************
23+
24+
Bugs Fixed
25+
**********
26+
27+
- **Config:** Added missing ``Config\Encryption::$cipher``.
28+
- **UserGuide:** Fixed the sample code for :ref:`encryption-compatible-with-ci3`.
29+
30+
See the repo's
31+
`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_
32+
for a complete list of bugs fixed.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
##############################
2+
Upgrading from 4.3.2 to 4.3.3
3+
##############################
4+
5+
Please refer to the upgrade instructions corresponding to your installation method.
6+
7+
- :ref:`Composer Installation App Starter Upgrading <app-starter-upgrading>`
8+
- :ref:`Composer Installation Adding CodeIgniter4 to an Existing Project Upgrading <adding-codeigniter4-upgrading>`
9+
- :ref:`Manual Installation Upgrading <installing-manual-upgrading>`
10+
11+
.. contents::
12+
:local:
13+
:depth: 2
14+
15+
Breaking Changes
16+
****************
17+
18+
Mandatory File Changes
19+
**********************
20+
21+
Project Files
22+
*************
23+
24+
Some files in the **project space** (root, app, public, writable) received updates. Due to
25+
these files being outside of the **system** scope they will not be changed without your intervention.
26+
27+
There are some third-party CodeIgniter modules available to assist with merging changes to
28+
the project space: `Explore on Packagist <https://packagist.org/explore/?query=codeigniter4%20updates>`_.
29+
30+
Content Changes
31+
===============
32+
33+
The following files received significant changes (including deprecations or visual adjustments)
34+
and it is recommended that you merge the updated versions with your application:
35+
36+
Config
37+
------
38+
39+
- app/Config/Encryption.php
40+
- The missing property ``$cipher`` is added for CI3
41+
Encryption compatibility. See :ref:`encryption-compatible-with-ci3`.
42+
43+
All Changes
44+
===========
45+
46+
This is a list of all files in the **project space** that received changes;
47+
many will be simple comments or formatting that have no effect on the runtime:
48+
49+
- @TODO

user_guide_src/source/installation/upgrading.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ See also :doc:`./backward_compatibility_notes`.
1616

1717
backward_compatibility_notes
1818

19+
upgrade_433
1920
upgrade_432
2021
upgrade_431
2122
upgrade_430

user_guide_src/source/libraries/encryption.rst

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,18 @@ Configuring the Library
6161

6262
The example above uses the configuration settings found in **app/Config/Encryption.php**.
6363

64-
============== ========================================================
64+
============== ==========================================================================
6565
Option Possible values (default in parentheses)
66-
============== ========================================================
66+
============== ==========================================================================
6767
key Encryption key starter
6868
driver Preferred handler, e.g., OpenSSL or Sodium (``OpenSSL``)
69-
blockSize Padding length in bytes for SodiumHandler (``16``)
7069
digest Message digest algorithm (``SHA512``)
71-
encryptKeyInfo Encryption key info (``''``). This is only used by OpenSSLHandler.
72-
authKeyInfo Authentication key info (``''``). This is only used by OpenSSLHandler.
73-
rawData Whether the cipher-text should be raw (``true``). This is only used by OpenSSLHandler.
74-
============== ========================================================
70+
blockSize [**SodiumHandler** only] Padding length in bytes (``16``)
71+
cipher [**OpenSSLHandler** only] Cipher to use (``AES-256-CTR``)
72+
encryptKeyInfo [**OpenSSLHandler** only] Encryption key info (``''``)
73+
authKeyInfo [**OpenSSLHandler** only] Authentication key info (``''``)
74+
rawData [**OpenSSLHandler** only] Whether the cipher-text should be raw (``true``)
75+
============== ==========================================================================
7576

7677
You can replace the config file's settings by passing a configuration
7778
object of your own to the ``Services`` call. The ``$config`` variable must be
@@ -281,7 +282,7 @@ Class Reference
281282

282283
Please refer to the :ref:`configuration` section for detailed info.
283284

284-
.. php:interface:: CodeIgniter\\Encryption\\EncrypterInterface
285+
.. php:interface:: CodeIgniter\Encryption\EncrypterInterface
285286
286287
.. php:method:: encrypt($data[, $params = null])
287288
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?php
22

3-
$encrypter = $encryption->initialize(['cipher' => '3des']);
3+
$encrypter = $encryption->initialize(['cipher' => 'AES-256-CTR']);

user_guide_src/source/libraries/encryption/013.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55

66
$config = new Encryption();
77
$config->driver = 'OpenSSL';
8-
// Your CI3's encryption_key
9-
$config->key = hex2bin('64c70b0b8d45b80b9eba60b8b3c8a34d0193223d20fea46f8644b848bf7ce67f');
8+
9+
// Your CI3's 'encryption_key'
10+
$config->key = hex2bin('64c70b0b8d45b80b9eba60b8b3c8a34d0193223d20fea46f8644b848bf7ce67f');
11+
// Your CI3's 'cipher' and 'mode'
12+
$config->cipher = 'AES-128-CBC';
13+
1014
$config->rawData = false;
1115
$config->encryptKeyInfo = 'encryption';
1216
$config->authKeyInfo = 'authentication';

0 commit comments

Comments
 (0)