defuse/php-encryption

Fatal error: Uncaught Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException: Ciphertext has invalid hex encoding. in /var/www/optinforlife/PatientApp/ci/application/vendor/defuse/php-encryption/src/Crypto.php on line 297

grey1090 opened this issue · 6 comments

hey guys, so Im getting this error:
Fatal error: Uncaught Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException: Ciphertext has invalid hex encoding. Defuse\Crypto\Crypto::decryptInternal('John', Object(Defuse\Crypto\KeyOrPassword), false):
Im pretty sure that its an issue with my key. any suggestions on how i resolve this, also in my ciphertext i'm passing in a string as per the docs.

Can you please provide an example of the code you're using? (Make sure not to post a key that you're actually using to encrypt data). That will help me understand what's going wrong. Thanks!

Oh, Defuse\Crypto\Crypto::decryptInternal('John', Object(Defuse\Crypto\KeyOrPassword), false) this part doesn't make sense to me, the correct way to call that API would be for John here to be the ciphertext and Object(Defuse\Crypto\KeyOrPassword) to instead be the key (string). Are you trying to decrypt data you've encrypted with an older version of this library?

the version of the library that I'am using is 2.2.1 i'm not sure if that is the older version or the newest. due to policy i'm not allowed to post any of my companies code in a public forum. Im encrypting form a different library mcrypt.

From the documentation i gathered that the $ciphertext should be a string, the $key should be an object, and $rawbinary the boolean. is that not correct?
in this case "John" is my ciphertext.

Sorry disregard that I misread decryptInternal as legacyDecrypt and got confused.

  • The ciphertext should be a string, but it needs to be a valid ciphertext that was created by encrypting some data using Crypto::encrypt(). If you're setting $raw_binary = true then it's probably trying to hex-decode John which will fail because it's not hex.
  • The key needs to be an instance of Key which you can get by calling Key::createNewRandomKey() or doing that, serializing it with savetoAsciiSafeString, then loading it with Key::loadFromAsciiSafeString().

I think the root of the problem is John isn't a valid ciphertext.

Closing due to inactivity, please reopen if you still need help!