0

Trying to decrypt a single des encrypted data using this code:

$keyValue ='0123456789abcdef'; //hex value
$encryptedOrderId = '88C10F0B8C084E5F'; //hex value
$binaryEncrypted = hex2bin($encryptedOrderId);
$decodeValueByOnlineTool = '2020202039353538';  // this is hex
$opensslDecrypt = openssl_decrypt(  $encryptedOrderId  ,'DES-ECB', $keyValue, OPENSSL_RAW_DATA , '' );
var_dump($opensslDecrypt);

The output is false. I do not know what wrong I'm doing.

The output from my tool is as follows: enter image description here

8
  • Do you not find it odd that you aren't using keyValue in your call to openssl_decrypt? Did you actually write that code or have you copied it from somewhere without understanding it? I suggest you read the docs for openssl_decrypt. Commented Jan 18, 2018 at 6:20
  • sorry for that I some how deleted it from my code check my updates. Commented Jan 18, 2018 at 6:23
  • DES keys are 64-bits (including parity) in length but the (hint: hex) string that you are passing in is interpreted as being 128-bits. Can you figure out what is wrong from that? Obviously the warning you have is relevant too. Commented Jan 18, 2018 at 6:24
  • not actually ,please give an answer if it works i'll mark it correct. you mean to say I need to convert it to binary? Commented Jan 18, 2018 at 6:25
  • Yes, you do. And fix the IV. I think that one is self explanatory. Commented Jan 18, 2018 at 6:27

1 Answer 1

3

Your inputs are in hex. openssl_decrypt expects binary. Use hex2bin on each input before passing to openssl_decrypt.

openssl_decrypt(hex2bin($encryptedOrderId), 'DES-ECB', hex2bin($keyValue), ...

Remember to convert the result back into hex to get the result you want. Make sure you've set OPENSSL_ZERO_PADDING as per your screenshot.

EDIT: The exact code I used...

$keyValue ='0123456789abcdef'; //hex value
$encryptedOrderId = '88C10F0B8C084E5F'; //hex value
$binaryEncrypted = hex2bin($encryptedOrderId);
$decodeValueByOnlineTool = '2020202039353538';  // this is hex
$opensslDecrypt = openssl_decrypt( $binaryEncrypted  ,'des-ecb', hex2bin($keyValue), OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING , '');
var_dump($opensslDecrypt);
Sign up to request clarification or add additional context in comments.

9 Comments

I did that too. returns false.
With the no padding?
with OPENSSL_ZERO_PADDING in 4th parameter. empty string output
See the exact code I used above. Definitely works for me.
letme check it .
|

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.