本文介绍了OpenSSL [des-ede3-cbc]解密php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须接收一些使用共享密钥用3DES加密的数据。
我正在使用php7和openssl_decrypt函数,但无法重新创建发送给我的文档示例的结果。

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.

OpenSSL创建发送给我的数据的命令如下:

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=

我尝试使用在线工具解码 Ja79hWTRfBE =,并成功获取 123456。
(我使用了此工具:,带有输入文本(十六进制) 25aefd8564d17c11,函数:3DES,模式:CBC,密钥(十六进制)17839778773fadde0066e4578710928988398877bb123789,iv:00000000)

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 )

php代码:

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

var_dump给我bool(false)。

var_dump return me bool(false).

我在做什么错了?

推荐答案

我可以使用以下代码重现您的目标:

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;




  • 设置没有base64的数据

  • 使用DES-EDE3方法

  • 将密钥(从十六进制转换为字符串)

  • 这篇关于OpenSSL [des-ede3-cbc]解密php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 02:03