php - json_decode returns NULL on string that has passed through encryption -


I'm trying to secure information on its database and is the standard type of data JSON and I have some simple Mcrypt function that encrypts any text and decrypt, they are:

  function encrypt ($ key, $ data) {$ encrypted_data = mcrypt_cbc (MCRYPT_RIJNDAEL_192, $ Key, $ data, MCRYPT_ENCRYPT); Return base64_encode ($ encrypted_data); } Function decrypt ($ key, $ Ankripteddeta) {$ decrypt = mcrypt_cbc (MCRYPT_RIJNDAEL_192, the $, Base64_decode ($ Ankripteddeta), MCRYPT_DECRYPT); Return $ decrypt; }   

I have a valid JSON string and I tested json_decode without passing through encryption, and so am but when I encrypt it works It tries to decrypt then to json_decode , it only returns NULL .

I'm just now debugging it in a simple script:

  Include ("coreFunctions.php"); $ Arr = '{"number": "4646464646", "type": "home"}'; $ Key = "Ladida"; $ Lock = encrypt ($ key, $ arr); Var_dump ($ closed); Var_dump (json_decode (decrypt ($ key, $ lock), true));   

I verify the output of is decrypt same as if it was inside.

UPDATE
I have discovered the strlen () before and after the difference. So how can I make sure that it remains the same during the encryption process or after that it can fix it? "post-text" itemprop = "text">

bin2hex reads:
033303539222c2274797065223a22686f6d65227d00000000000000000000

This means that you Dulripted Let's emulate NUL bytes in the string. This happens because mcrybt_cbc operates block-wise. To do this, it must fill input and output in multiples of 16 or (24) bytes. (The output may sometimes waste; therefore, a length field often adds to the encryption schemes / container formats.)

In your AS you can get away with the application after decryption . Or more at all:

  json_decode (rtrim (decrypt ($ key, $ lock), "\ 0"), true);    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -