CodeIgniter Forums
Encryption Service - broken characters - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31)
+--- Thread: Encryption Service - broken characters (/showthread.php?tid=75363)



Encryption Service - broken characters - TonyC - 01-30-2020

Hello guys, I need help with the problem what i got.
When using the Encryption service and encrypt some data i always got improperly encoded characters.

For example


Code:
<a href="" charset="UTF-8" data-text="<?= $encrypter->encrypt(10) ?>">test</a>
produce
Code:
<a href="" charset="UTF-8" data-text="�c�NK���a�ǃ���:�0��8�m���v��C7��M�Y���v]s*���BL��t��M��Y����<c����I1�1�z�">test</a>

I´m using CI4 rc3 with config set to utf-8,PHP 7.2.26 running on localhost, developing in php storm which encoding is set to utf-8.
I tried output to log, print on screen, insert to db and i always a got broken chars.
Thank you very much for help.


RE: Encryption Service - broken characters - InsiteFX - 01-30-2020

I think you need to base64 encode and decode it.


RE: Encryption Service - broken characters - dave friend - 01-30-2020

(01-30-2020, 01:33 AM)TonyC Wrote: Hello guys, I need help with the problem what i got.
When using the Encryption service and encrypt some data i always got improperly encoded characters.

For example


Code:
<a href="" charset="UTF-8" data-text="<?= $encrypter->encrypt(10) ?>">test</a>
produce
Code:
<a href="" charset="UTF-8" data-text="�c�NK���a�ǃ���:�0��8�m���v��C7��M�Y���v]s*���BL��t��M��Y����<c����I1�1�z�">test</a>

I´m using CI4 rc3 with config set to utf-8,PHP 7.2.26 running on localhost, developing in php storm which encoding is set to utf-8.
I tried output to log, print on screen, insert to db and i always a got broken chars.
Thank you very much for help.

You need to convert the binary string that encryption outputs into hex. base64_encode and its compliment base64_decode is one solution. The other solution is to use the complementary functions bin2hex and hex2bin

Read the docs for more