I have encrypted data in PHP database. Data is encrypted using AES-128-CTR.Please note data is not encrypted using php-encrypt.I need to decrypt this data using openssl-decrypt().
I retrieve data from database as an array and pass this array onto foreach loop then pass each array value as string to the above function as needed but still there is array to string conversion error.
Let me know if it is possible to use AES-128-CTR mode of encryption/decryption possible. Also why does this array to string conversion error occur and what is the solution?
<?php
include "connect.php";
$query="select * from encrypted_data";
$rs=$dbhandle->query($query);
$key = hex2bin('2b7e151628aed2a6abf7157803cf5f3a');
$iv = hex2bin('f0f1f2f3f4f5f6f7f8f9fcfbf1fdfbfa');
while ($row = $rs->fetch_array()) {
$data['encrypted_data'] = $row;
}
foreach($data as $str)
{
$output = openssl_decrypt($str, 'AES-128-CTR', $key,OPENSSL_ZERO_PADDING, $iv);
echo $output;
}
?>