CodeIgniter Forums
Problem in AES - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Problem in AES (/showthread.php?tid=75956)



Problem in AES - omid_student - 04-01-2020

Hi
Why when i use below code for decryption,result is empty
PHP Code:
$this->load->library('encryption');
        
$this->encryption->initialize(
            array(
                
'cipher' => 'aes-256',
                
'mode' => 'cbc',
                
'key' => 'RfUjXn2r5u8x!A%D*G-KaPdSgVkYp3s6'
            
)
        );
        echo 
$this->encryption->decrypt('R0gyV2NwQEJ5ZVZKODVnaHYEbS37syFYTcQNdwMXMQo='); 

But when i use below code,it return correct result:
PHP Code:
function EncryptAES($message$key){
            
$ivsize openssl_cipher_iv_length('aes-256-cbc');
            
$iv openssl_random_pseudo_bytes($ivsize);
            
$ciphertext openssl_encrypt($message,'aes-256-cbc',$key,OPENSSL_RAW_DATA,$iv);

            return 
$iv $ciphertext;
      } 
Result must be omid
You can decrypt it in https://www.devglan.com/online-tools/aes-encryption-decryption
Thanks