Openssl aes-256 encrypted file on windows cannot be decrypted on linux

I have a php document repository application running on windows apache, this application will encrypt any downloaded document with the following command:

echo MyPass34 | openssl.exe aes-256-cbc -pass stdin -salt -in somefile.pdf -out somefile.pdf

and also decrypt them when they are downloaded using the following command:

echo MyPass34 | openssl.exe aes-256-cbc -pass stdin -d -in somefile.pdf -out decriptedfile.pdf

the application still works, people upload and download their files while they are encrypted on the server, now the problem is that this application was transferred to the Apache linux server, and now the files where they are encrypted on the windows are incorrectly decrypted on linux.

Why is this? Is there any way to configure the decryption command so that it decrypts these files again?

PS: New files that are encrypted in Linux are correctly decrypted, just like in Windows, this is the case with a decoded linux encoded window that does not work.

+3
source share
1 answer

I found a solution :-), the problem is that the echo windows command adds three characters to the end of the password, these are spaces, CR and LF characters, and the echo linux command does not seem to send these characters, and therefore the openssl command does not receive that same password that is used for encryption.

, Linux, , escape- . , , , Linux :

echo $'MyPass34\x20\x0d\x0a' | /usr/bin/openssl aes-256-cbc -pass stdin -d -in somefile.pdf -out decriptedfile.pdf

, -!

+6

Source: https://habr.com/ru/post/1786608/


All Articles