Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中,Openssl解密(DES)返回false_Php_Encryption - Fatal编程技术网

在PHP中,Openssl解密(DES)返回false

在PHP中,Openssl解密(DES)返回false,php,encryption,Php,Encryption,我试图用DES-ECB加密解密数据,但响应总是错误的 当我解密字符串时,通过响应是正确的。此网站在PHP中使用函数“mcrypt_encrypt()”,但此功能在我的服务器上不可用 我正在编写的代码应该可以在PHP7.1+版本上运行,因此我的系统中不再提供mcrypt_encrypt() $password = 'password'; // Example $decryptedString = 'ThisShouldBeAnTestToCheckIfTheStringIsCor

我试图用DES-ECB加密解密数据,但响应总是错误的

当我解密字符串时,通过响应是正确的。此网站在PHP中使用函数“mcrypt_encrypt()”,但此功能在我的服务器上不可用

我正在编写的代码应该可以在PHP7.1+版本上运行,因此我的系统中不再提供mcrypt_encrypt()

$password         = 'password'; // Example
$decryptedString  = 'ThisShouldBeAnTestToCheckIfTheStringIsCorrectDecryptedThroughDES-ECB'; 

// Encrypted the string through the online tool.
$encryptedString  = 'zOToWEkYOoDnNWZ/sWEgOQQAX97NTZami/3V18yeKmoKiuam3DL0+Pu/LIuvjJ52zbfEx/+6WR4JcCjIBojv0H1eYCDUwY3o';

$opensslDecrypt   = openssl_decrypt(base64_decode($encryptedString),'DES-ECB', $password);

var_dump($opensslDecrypt); // Returns false.

我还尝试在没有
base64\u decode
函数的情况下解密,但仍然返回false


有人知道为什么这不是应该进行的解密吗?

您必须精确指定方法调用中的
$options

只需在密码后添加以下参数:
OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING',


因此,如果我希望在不使用base64_decode的情况下转换字符串,那么应该使用如下函数,对吗<代码>$opensslDecrypt=openssl_decrypt($hash,'DES-ECB',$password,openssl_ZERO_PADDING',)就是你抓住的。你自己试试,你会发现它很管用
<?php

$password         = 'password';
$decryptedString  = 
'ThisShouldBeAnTestToCheckIfTheStringIsCorrectDecryptedThroughDES-ECB'; 

// Encrypted the string through the online tool.
$encryptedString  =  'zOToWEkYOoDnNWZ/sWEgOQQAX97NTZami/3V18yeKmoKiuam3DL0+Pu/LIuvjJ52zbfEx/+6WR4JcCjIBojv0H1eYCDUwY3o';

$opensslDecrypt   = openssl_decrypt(base64_decode($encryptedString),'DES-ECB', $password, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING , '');

var_dump(trim($opensslDecrypt));