用十六进制键从十六进制数据解密3des [英] Decrypting 3des from hex data with a hex key

查看:925
本文介绍了用十六进制键从十六进制数据解密3des的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用mycrypt php库来解密以下内容:

I am trying to use the mycrypt php library to decrypt the following:


密钥: aaaaaaaabbbbbbbccccccccdddddddd

Key: aaaaaaaabbbbbbbbccccccccdddddddd

数据: b5057bbc04b842a96144a0f617f2820e

Data: b5057bbc04b842a96144a0f617f2820e

预期结果 Test123123

Expected Result: Test123123

使用模式ECB对3DES进行数据加密。我正在使用的代码将十六进制值解密为e2119b734b5050e3,转换为sKPPã。我已经尝试使用打开ssl返回False。

The data is encrypted with 3DES with the mode ECB. The code I'm currently working with decrypts the hex value to "e2119b734b5050e3" which translates to "â›sKPPã". I have tried using open ssl which is returning "False".

代码如下:

(PHP版本5.3.3)

(PHP Version 5.3.3)

$key = 'aaaaaaaabbbbbbbbccccccccdddddddd';
$key = pack('H*',$key);

// DATA
$data = 'b5057bbc04b842a96144a0f617f2820e';
$data = pack('H'.strlen($key),$data);

// DECRYPT MCRYPT
$data = rtrim(mcrypt_decrypt(MCRYPT_3DES, $key, $data, MCRYPT_MODE_ECB), "\0");
$decryptedHex = unpack('H*',$data);

// DECRYPT OPEN SSL (RETURNS FALSE)
$result = openssl_decrypt($data,'des-ede3', $key);

// ECHO
echo $decryptedHex[1];


推荐答案

这里的问题是缺少信息太多 - 3DES的确切变体,填充信息。有一点点加密选项,而不是解密可以尝试生成密文找到正确的选项。他们原来是

The problem here is that there is too much missing information - the exact variant of 3DES, the padding info. With a little fiddling with encrypting options, rather than decrypting one can try to generate the ciphertext to find the correct options. They turn out to be

openssl_encrypt($ptext,'des-ede', $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING)

其中 $ ptext Test123123\0\0\0\0\0\0

密文可以类似地通过

$result = openssl_decrypt($data,'des-ede', $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING);

您将需要升级到更新和支持(PHP 5.3于2009年发布,不是更长时间支持到2015年)版本的PHP。

You will need to upgrade to a more recent and supported (PHP 5.3 was released in 2009 and is no longer supported as of 2015) version of PHP.

这篇关于用十六进制键从十六进制数据解密3des的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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