|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26733 End of an array created by explode corrupted
Submitted: 2003-12-28 14:01 UTC Modified: 2003-12-28 14:13 UTC
From: n0spam_socrate_omega at hotmail dot com Assigned:
Status: Not a bug Package: mcrypt related
PHP Version: 4.3.4 OS: Windows XP Home/Pro
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: n0spam_socrate_omega at hotmail dot com
New email:
PHP Version: OS:


 [2003-12-28 14:01 UTC] n0spam_socrate_omega at hotmail dot com
I have a string encrypted with mcrypt and encoded in base64. I unbase64 this string and I decrypt it using mcrypt. I got the exact same string but when I try to explode it into an array with the explode() function, I cannot make comparison == with the last element of the newly created array.

Reproduce code:
$key = "validkey";
$input = base64_decode($txtEncrypted);	
$decrypted = mcrypt_ecb(MCRYPT_RIJNDAEL_128, $key, $input, MCRYPT_DECRYPT);

echo $decrypted."<br>";

$array_data = explode('||', $decrypted);

echo "|".$array_data."|<br>";

if ($array_data[8] == 'end') {
   echo "it works!";

Expected result:
it works!

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-12-28 14:12 UTC]
This is not a bug. If you use a block cipher like Rijndael then mcrypt needs to pad your data with zeroes to fill up the whole block to encrypt. If you are decrypting the encrypted string those trailing zeroes are still there, and thus the comparison of the last element fails. 

Before you start asking if we can't trim the string while decrypting; no this is not possible because we don't know if you are encrypting binary data (which might end in a zero) or not. You'll have to take care of this yourself then by using rtrim during comparison.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 11:01:28 2024 UTC