问题
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