【问题标题】:Decrypt data encrypted with MCRYPT_RIJNDAEL_128解密使用 MCRYPT_RIJNDAEL_128 加密的数据
【发布时间】:2018-11-17 16:59:00
【问题描述】:

CCAvenue 使用 MCRYPT_RIJNDAEL_128 来加密交易数据。由于我的服务器运行的是 PHP 7.1,我无法解密这些数据。

是否有任何解决方法可以在 PHP 7.1 上解密此字符串,或者我是否必须降级到 PHP 5 才能使其正常工作。

来自 ccavenue 的解密代码

    function decrypt($encryptedText,$key)
    {
        $secretKey = hextobin(md5($key));
        $initVector = pack("C*", 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f);
        $encryptedText=hextobin($encryptedText);
        $openMode = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '','cbc', '');
        mcrypt_generic_init($openMode, $secretKey, $initVector);
        $decryptedText = mdecrypt_generic($openMode, $encryptedText);
        $decryptedText = rtrim($decryptedText, "\0");
        mcrypt_generic_deinit($openMode);
        return $decryptedText;

    }

解密响应

Call to undefined function mcrypt_module_open()

【问题讨论】:

标签: php openssl mcrypt ccavenue


【解决方案1】:

好的。轮到我们的 CCAvenue 推出了 PHP 7.1 兼容版本。

Open SSL 兼容版本的代码

function encrypt($plainText,$key)
{
  $key = hextobin(md5($key));
  $initVector = pack("C*", 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f);
  $openMode = openssl_encrypt($plainText, 'AES-128-CBC', $key, OPENSSL_RAW_DATA, $initVector);
  $encryptedText = bin2hex($openMode);
  return $encryptedText;
}

function decrypt($encryptedText,$key)
{
  $key = hextobin(md5($key));
  $initVector = pack("C*", 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f);
  $encryptedText = hextobin($encryptedText);
  $decryptedText = openssl_decrypt($encryptedText, 'AES-128-CBC', $key, OPENSSL_RAW_DATA, $initVector);
  return $decryptedText;

}

【讨论】:

【解决方案2】:

尝试使用 openssl_encrypt($input, 'AES-128-CBC', "KEY", OPENSSL_RAW_DATA, $iv);

【讨论】:

  • 试过了。我得到一个错误的回应
  • mcrypt 在 php7.1 中已弃用,但我认为它尚未删除。
  • 不。我收到“调用未定义函数 mcrypt_module_open()”错误
  • 您是否安装并启用了 mcrypt in
  • 不热衷于在我的新项目上安装折旧的库。如果一切都失败了,那将是最后的选择
猜你喜欢
  • 1970-01-01
  • 2017-01-03
  • 1970-01-01
  • 2010-10-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-07
相关资源
最近更新 更多