Skip to content
Advertisement

openssl_decrypt returns blank

I tried the following code

JavaScript

and getting the following output

JavaScript

The decrypt string ($output1) is blank.

Advertisement

Answer

Your code is running well but the input data to your decrypt functionality is wrong.

You are feeding the openssl_decrypt function with the (original) plaintext and not with the data encrypted by openssl_encrypt (“output”).

Just a friendly information regarding the security of your code: as you are using the AES algorithm in mode “CBC” it is necessary to use a random generated initialization vector (“iv”) or your complete encryption gets vulnerable.

This will be the output of your encryption/decryption:

JavaScript

complete code:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement