Skip to content

Commit bc297ff

Browse files
committed
config: add missing $cipher
1 parent 246a7af commit bc297ff

4 files changed

Lines changed: 43 additions & 11 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/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

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)