OpenSSL [des-ede3-cbc] Decryption php

六月ゝ 毕业季﹏ 提交于 2020-01-05 07:04:21

问题


i had to receive some data encrypted with 3DES with shared keys. I'm using php7 and openssl_decrypt function, but I'm not able to recreate the result of the example of the documentation sent to me.

The OpenSSL command that create the data sent to me is the following:

openssl enc -des-ede3-cbc -base64 -K 17839778773fadde0066e4578710928988398877bb123789 -iv 00000000 -in D:/in.txt

Example:
string_encoded: 123456
data_to_decrypt: Ja79hWTRfBE=

I tried to decode "Ja79hWTRfBE=" with an online tool and I successfully obtain "123456". (I used this tool: http://tripledes.online-domain-tools.com/ with input text (hex) "25aefd8564d17c11", function: 3DES, mode: CBC, key (hex) 17839778773fadde0066e4578710928988398877bb123789, iv: 00000000 )

Below my php code:

$key = "17839778773fadde0066e4578710928988398877bb123789";
$decData = openssl_decrypt(base64_decode('Ja79hWTRfBE='), 'DES-EDE3-CBC', $key, 0, "00000000");
var_dump($decData);

var_dump return me bool(false).

What am i doing wrong?


回答1:


i can reproduce your goal with the following code:

<?php

$data = "123456";
$method = "DES-EDE3";
$key = "17839778773fadde0066e4578710928988398877bb123789";
$options = 0;

// transform the key from hex to string
$key = pack("H*", $key);

// encrypt
$enc = openssl_encrypt($data, $method, $key, $options);
// decrypt
$dec = openssl_decrypt($enc, $method, $key, $options);

echo "plain: ".$data." encrypted: ".$enc." decrypted: ".$dec;
  • set data without base64
  • use DES-EDE3 method
  • transform your key (from hex to string)


来源:https://stackoverflow.com/questions/54420126/openssl-des-ede3-cbc-decryption-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!