D
D
Dmitry Zubkov2015-07-01 18:07:24
PHP
Dmitry Zubkov, 2015-07-01 18:07:24

How to get same mcrypt encryption results in php and in console?

There is a standard implementation of encryption with mcrypt in php (DES with ECB mod):

var_dump(base64_encode(mcrypt_encrypt('des', 'abcd1234', 12345, 'ecb')));

which always returns the same result: It is vital to get exactly the same result when working with mcrypt through the command line. Having smoked the manual, there was some confidence that the analogue of the above code in php in the console should look like this:string(12) "TkXoGeZK44Y="
mcrypt -a des -m ecb -b -q -F -k 'abcd1234' | base64

But the result obtained does not match the result that was obtained above. I get either JWzYLaNSAOc=or L0BJcpSopZU=, depending on whether I do a line break before Ctrl+D.
The current php implementation cannot be modified, so it is the console version that needs to be fixed.
I would be extremely grateful if you point out an error in my results!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vlad Zhivotnev, 2015-07-01
@inkvizitor68sl

> depending on whether I am doing a line break before Ctrl+D.
The line break is quite a character, so it gets into the data from which the hash is calculated.
Pass through sed 's/^$//g' , for example.

A
Alexander Karabanov, 2015-07-02
@karabanov

Can solve the problem "on the forehead":

$ php -r "echo base64_encode(mcrypt_encrypt('des', 'abcd1234', '12345', 'ecb'));"
TkXoGeZK44Y=

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question