Welcome Guest, Not a member yet? Register   Sign In
Encrypter causing Failedtoparsejsonstring Exception
#1

Hello all,

I would like to use encrypter service however it causes "forInvalidJSON('MalformedUTF-8...')" error.

I have configured the encryption key and left provider as OpenSSL in config. Any help appriciated.

Code:
Code:
$arr=['encryptedKey'=>service('encrypter')->encrypt('Deneme123')];

Error:
Code:
<br/><b>Fatalerror</b>: UncaughtCodeIgniter\Format\Exceptions\FormatException: Failedtoparsejsonstring,
error: &quot;MalformedUTF-8characters,
possiblyincorrectlyencoded&quot;.in/home/admin/web/api.sandbox.com/public_html/v1/vendor/codeigniter4/framework/system/Format/Exceptions/FormatException.php: 9Stacktrace: #0/home/admin/web/api.sandbox.com/public_html/v1/vendor/codeigniter4/framework/system/Format/JSONFormatter.php(67): CodeIgniter\Format\Exceptions\FormatException: : forInvalidJSON('MalformedUTF-8...')#1/home/admin/web/api.sandbox.com/public_html/v1/vendor/codeigniter4/framework/system/API/ResponseTrait.php(414): CodeIgniter\Format\JSONFormatter-&gt;format(Array)#2/home/admin/web/api.sandbox.com/public_html/v1/vendor/codeigniter4/framework/system/API/ResponseTrait.php(134): CodeIgniter\Debug\Exceptions-&gt;format(Array)#3/home/admin/web/api.sandbox.com/public_html/v1/vendor/codeigniter4/framework/system/Debug/Exceptions.php(166): CodeIgniter\Debug\Exceptions-&gt;respond(Array,
500)#4[
  internalfunction
]: CodeIgniter\Debug\Exceptioin<b>/home/admin/web/api.sandbox.com/public_html/v1/vendor/codeigniter4/framework/system/Format/Exceptions/FormatException.php</b>online<b>9</b><br/>{
  "title": "ErrorException",
  "type": "ErrorException",
  "code": 500,
  "message": "Uncaught CodeIgniter\\Format\\Exceptions\\FormatException: Failed to parse json string, error: \"Malformed UTF-8 characters, possibly incorrectly encoded\". in /home/admin/web/api.sandbox.com/public_html/v1/vendor/codeigniter4/framework/system/Format/Exceptions/FormatException.php:9\nStack trace:\n#0 /home/admin/web/api.sandbox.com/public_html/v1/vendor/codeigniter4/framework/system/Format/JSONFormatter.php(67): CodeIgniter\\Format\\Exceptions\\FormatException::forInvalidJSON('Malformed UTF-8...')\n#1 /home/admin/web/api.sandbox.com/public_html/v1/vendor/codeigniter4/framework/system/API/ResponseTrait.php(414): CodeIgniter\\Format\\JSONFormatter->format(Array)\n#2 /home/admin/web/api.sandbox.com/public_html/v1/vendor/codeigniter4/framework/system/API/ResponseTrait.php(134): CodeIgniter\\Debug\\Exceptions->format(Array)\n#3 /home/admin/web/api.sandbox.com/public_html/v1/vendor/codeigniter4/framework/system/Debug/Exceptions.php(166): CodeIgniter\\Debug\\Exceptions->respond(Array, 500)\n#4 [internal function]: CodeIgniter\\Debug\\Exceptio",
  "file": "/home/admin/web/api.sandbox.com/public_html/v1/vendor/codeigniter4/framework/system/Format/Exceptions/FormatException.php",
  "line": 9,
  "trace": [
    {
      "function": "shutdownHandler",
      "class": "CodeIgniter\\Debug\\Exceptions",
      "type": "->",
      "args": []
    }
  ]
}
Reply
#2

It is quite annoying that I never pass the encrypted non UTF-8 data to response. It is being handled in the model. However, I created my solution is by base64 encoding the encrypted data.

Maybe adding base64_encode output and pre base64_decode options would be a good idea to Encryption Interface.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB