在PHP中使用openssl_decrypt解密des [英] Decrypt des with openssl_decrypt in PHP

查看:1681
本文介绍了在PHP中使用openssl_decrypt解密des的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用以下代码解密单个des加密数据:

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:

推荐答案

您的输入为十六进制。 openssl_decrypt 期望为二进制。在传递给 openssl_decrypt 之前,在每个输入上使用 hex2bin

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), ...

请记住将结果转换回十六进制以获得所需的结果。请确保已根据您的要求设置了 OPENSSL_ZERO_PADDING 截图。

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.

编辑:我使用的确切代码...

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);

这篇关于在PHP中使用openssl_decrypt解密des的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆