openssl_decrypt only works sometimes when output passed to another php page

Dan471

New member
I am having a problem passing an encrypted string to another source file in PHP. I am using openssl_encrypt and openssl_decrypt. I have 4 PHP source files. Index.php, page2.php (the file I am calling), decrypt.php and encrypt.php.

In my test, I am using all standard ASCII characters, a→z and 1 number. No special characters i.e. &$/. etc. I am using windows 11 with WAMP.

The problem I am having is when I pass an encrypted string to the second sour file, sometimes it will decrypt it correctly. If I change just 1 character in the middle of the string, pass the encrypted string to the second file, the decrypt function returns a null string.

In Index.php, you can comment out or remove comment slashes on the variable ‘$gg3’ to see what happens.

What makes the test interesting is with the $mode variable.

If $mode = 1, it calls the second source file and sometimes the decryption works. Change 1 character in the middle of the string and it fails as described above.

If you uncomment $mode = 2 and run it, everything works and anything that failed in $mode = 1 now works correctly. Every time.

I could understand something else was wrong, if in $mode = 1, the decrypt failed every time, but it sometimes it works and sometimes it failes.


Any help would be appreciated.

Thanks Dan471
 
Back
Top