I use the following code to generate a encrypted string for a given string.
class MY_class{
public static function cryption($string){
$output = base64_encode(openssl_encrypt($string, $cipher_method, $key, 0, $iv));
$output = $iv . $output;
return $output;
}
}
Using this code I generated the encrypted id of the id of a model object and replaced the original id.
$Model_object = Model_class::find(1);
$Model_object->id = MY_class::cryption($Model_object->id);
echo json_encode($Model_object);
For a given instance print_r()
of $Model_object
after replacing the original id with encrypted id gives me the following result.
[index] => Array
(
[id] => 4df73f34cUYxVmVLWlFUU2M9
)
But json_encode()
only outputs only the first decimal digits of the of the encrypted id.
{"id":4}
I'd really appreciate if someone can explain why this is happening and how to overcome this problem.
P.S. I have already googled this problem and searched in Stack Overflow too. So, don't mention it in comments.