Skip to content
Advertisement

How to encrypt with openSLL using the DES-CBC method

Actually I’m using Mcrypt but I’m moving to OpenSSL and I need to be able to use it the exact same way as Mcrypt.

This is how I’m encrypting

JavaScript

For the decryption, I already managed to do it in OpenSSL, both are working the same exact ways

JavaScript

For the encryption using OpenSSL, this is my test code

JavaScript

And this is the output :

JavaScript

This is the official list of method, but I can’t find the DES methods.

I know that Openssl declared DES weak, but I still need to use it in my situation.

How can I encrypt in DES-CBC using OpenSSL and make it behave the same way as the Mcrypt fonction ?

Edit:

If I removed the OPENSSL_ZERO_PADDING option, the result is almost the one expected

Code:

JavaScript

output:

JavaScript

The first part of the string is correct but at the end it differs from the output of the Mcrypt encryption string.

Advertisement

Answer

Thanks to @Topaco I managed to make it work

I added the OPENSSL_ZERO_PADDING option to disable the PKCS7 padding, then I created a function to manually pad my string with 0x00

JavaScript

Output:

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