Upgrade Encryption¶
What has been changed¶
- The support for
MCrypt
has been dropped, as that has been deprecated as of PHP 7.2.
Upgrade Guide¶
- Within your configs the
$config['encryption_key'] = 'abc123';
moved fromapplication/config/config.php
topublic $key = 'abc123';
inapp/Config/Encryption.php
. - Wherever you have used the encryption library you have to replace
$this->load->library('encryption');
with$encrypter = service('encrypter');
and change the methods for encryption and decrypting like in the following code example.
Code Example¶
Codeigniter Version 3.11¶
$this->load->library('encryption');
$plain_text = 'This is a plain-text message!';
$ciphertext = $this->encryption->encrypt($plain_text);
// Outputs: This is a plain-text message!
echo $this->encryption->decrypt($ciphertext);
Codeigniter Version 4.x¶
$encrypter = service('encrypter');
$plainText = 'This is a plain-text message!';
$ciphertext = $encrypter->encrypt($plainText);
// Outputs: This is a plain-text message!
echo $encrypter->decrypt($ciphertext);