Skip to content

Commit e9e9fdd

Browse files
authored
Merge pull request #611 from jim-parry/rework/encryption
Rework/encryption
2 parents 19c173a + b30d019 commit e9e9fdd

9 files changed

Lines changed: 508 additions & 814 deletions

File tree

application/Config/Encryption.php

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Encryption extends BaseConfig
1515
{
1616
/*
1717
|--------------------------------------------------------------------------
18-
| Encryption Key
18+
| Encryption Key Starter
1919
|--------------------------------------------------------------------------
2020
|
2121
| If you use the Encryption class you must set an encryption key.
@@ -30,27 +30,40 @@ class Encryption extends BaseConfig
3030
| Encryption driver to use
3131
|--------------------------------------------------------------------------
3232
|
33-
| One of the supported drivers, eg 'openssl' or 'mcrypt'.
34-
| The default driver, if you don't specify one, is 'openssl'.
33+
| One of the supported drivers, eg 'OpenSSL' or 'Sodium'.
34+
| The default driver, if you don't specify one, is 'OpenSSL'.
3535
*/
36-
public $driver = 'openssl';
36+
public $driver = 'OpenSSL';
3737

3838
/*
3939
|--------------------------------------------------------------------------
4040
| Encryption Cipher
4141
|--------------------------------------------------------------------------
4242
|
43-
| Name of the encryption cipher to use, eg 'aes-256' or 'blowfish'
43+
| Name of the encryption cipher to use, eg 'aes-256' or 'blowfish'.
44+
| The cipher must be supported by your designated driver.
4445
*/
45-
public $cipher = 'aes-256';
46+
public $cipher = 'AES-256-CBC';
4647

4748
/*
4849
|--------------------------------------------------------------------------
49-
| Encryption mode
50+
| Authentication digest
5051
|--------------------------------------------------------------------------
5152
|
52-
| The encryption mode to use, eg 'cbc' or 'stream'
53+
| HMAC digest algorithm to use, empty for none.
54+
| Values: SHA512, SHA384, SHA256, or SHA224.
5355
*/
54-
public $mode = 'cbc';
56+
public $digest = 'SHA512';
57+
58+
/*
59+
|--------------------------------------------------------------------------
60+
| Result encoding
61+
|--------------------------------------------------------------------------
62+
|
63+
| Which, if any, encoding to apply to encrypted results and to assume
64+
| provided ciphertext.
65+
| Values; empty (for no encoding), base64 or hex.
66+
*/
67+
public $encoding = 'base64';
5568

5669
}

system/Config/AutoloadConfig.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ public function __construct()
144144
'CodeIgniter\Debug\Timer' => BASEPATH . 'Debug/Timer.php',
145145
'CodeIgniter\Debug\Iterator' => BASEPATH . 'Debug/Iterator.php',
146146
'CodeIgniter\Encryption\Encryption' => BASEPATH . 'Encryption/Encryption.php',
147+
'CodeIgniter\Encryption\EncrypterInterface' => BASEPATH . 'Encryption/EncrypterInterface.php',
148+
'CodeIgniter\Encryption\Handlers\BaseHandler' => BASEPATH . 'Encryption/Handlers/BaseHandler.php',
149+
'CodeIgniter\Encryption\Handlers\OpenSSLHandler' => BASEPATH . 'Encryption/Handlers/OpenSSLHandler.php',
147150
'CodeIgniter\Events\Events' => BASEPATH . 'Events/Events.php',
148151
'CodeIgniter\HTTP\CLIRequest' => BASEPATH . 'HTTP/CLIRequest.php',
149152
'CodeIgniter\HTTP\ContentSecurityPolicy' => BASEPATH . 'HTTP/ContentSecurityPolicy.php',

system/Encryption/EncrypterInterface.php

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,16 @@ interface EncrypterInterface
4848
* Encrypt - convert plaintext into ciphertext
4949
*
5050
* @param string $data Input data
51-
* @param array $params Input parameters
5251
* @return string
5352
*/
54-
public function encrypt($data, array $params = null);
53+
public function encrypt($data);
5554

5655
/**
5756
* Decrypt - convert ciphertext into plaintext
5857
*
5958
* @param string $data Encrypted data
60-
* @param array $params Input parameters
6159
* @return string
6260
*/
63-
public function decrypt($data, array $params = null);
61+
public function decrypt($data);
6462

65-
/**
66-
* Create an HKDF random key
67-
*
68-
* @link https://tools.ietf.org/rfc/rfc5869.txt
69-
* @param $key Input key
70-
* @param $digest A SHA-2 hashing algorithm
71-
* @param $salt Optional salt
72-
* @param $length Output length (defaults to the selected digest size)
73-
* @param $info Optional context/application-specific info
74-
* @return string A pseudo-random key
75-
*/
76-
public function hkdf($key, $digest = 'sha512', $salt = null, $length = null, $info = '');
7763
}

0 commit comments

Comments
 (0)