Welcome Guest, Not a member yet? Register   Sign In
CI 3 to CI 4 Encryption Compability
#1

(This post was last modified: 07-17-2022, 11:10 AM by ardimardiana.)

I have 1 app for SSO, use CI 3. Now i am creating new app with CI 4. code in CI 3 for encryption :

Code:
$otp = 123;
$this->encryption->initialize(array(   
    'cipher' => 'aes-256',
    'mode' => 'ctr',
    'key' => '12345678901234567890123456789012'
));
echo $this->encryption->encrypt($otp);
//result 54322c75199be967a78c4d65906dd1d6a41c54027ddb2ff1a295c5646728f435cf4c3b5e793b57b6a6ecef34de7b7c1ed809632adeb02c5fabdf5f76befe4440PFRX6XAktE/jZXJKjL8fhCcqQw==

code in CI 4 for decryption :

Code:
$otp = '54322c75199be967a78c4d65906dd1d6a41c54027ddb2ff1a295c5646728f435cf4c3b5e793b57b6a6ecef34de7b7c1ed809632adeb02c5fabdf5f76befe4440PFRX6XAktE/jZXJKjL8fhCcqQw==';

$config        = new \Config\Encryption();
$config->key    = '12345678901234567890123456789012';
$config->driver = 'OpenSSL';
$encrypter = \Config\Services::encrypter($config);
echo $encrypter->decrypt($otp);

//result CodeIgniter\Encryption\Exceptions\EncryptionException Decrypting: authentication failed.

i have try with different option :

Code:
$config        = new \Config\Encryption();
$config->key    = '12345678901234567890123456789012';
$config->driver = 'OpenSSL';
$config->digest = 'sha256' or 'sha512';

Still getting message authentication failed. but in this documentation states that my CI 3 configuration it same with CI 4 even with default.

i noticed some different between CI3 and CI4 on Encryption Lib. There is something about BASE64 decode and encode in CI3 for encrypt or decrypt.
i have red in this Github Issue, something aboout bin2hex and hex2bin. and try it at my decrypt like : 


Code:
echo $this->encryption->encrypt(base64_decode($otp));
echo $this->encryption->encrypt(hex2bin($otp));

but still getting authentication failed.

note:
i cant rewrite my CI3 SSO because it has many another app using CI3.
Reply


Messages In This Thread
CI 3 to CI 4 Encryption Compability - by ardimardiana - 07-17-2022, 07:18 AM



Theme © iAndrew 2016 - Forum software by © MyBB