0

I'm using the following method to decrypt the data,

$clear = openssl_decrypt($data, 'aes-256-cbc', $pass, 0, $iv);

$iv is always null, but it works

But when I use openssl to decrypt the same file (the data is base64 encoded),

openssl aes-256-cbc -d -a -in encrypted

After inputing the password, it says error reading input file, totally weird error

Any ideas?

1
  • Maybe you need to add the -base64 flag? Commented Feb 28, 2017 at 3:55

1 Answer 1

1

In PHP $pass is actually the full binary key. The openssl utility expects the actual password. You might want to use

openssl aes-256-cbc -d -a -in encrypted -K <hex-encoded key> -nosalt -iv 00000000000000000000000000000000
Sign up to request clarification or add additional context in comments.

3 Comments

I've tried openssl 1.1, openssl 1.0.2 and 0.9.8, none of them have the -noiv command line option
The $pass is a user input, e.g abcdefg, so PHP transformed it to binary key?
It probably silently pads it with 0x00 bytes until the key has 256 bit. In your case abcdefg\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.