/**
* 16进制转字符串
* @param string $hex
* @return string
*/
public function hexToStr(string $hex)
{
$string = "";
for ($i = 0; $i < strlen($hex) - 1; $i += 2)
$string .= chr(hexdec($hex[$i] . $hex[$i + 1]));
return $string;
}
/**
* 解密
* @param string $str
* @param string $key
* @return string
*/
public function desDecrypt(string $str, string $key)
{
$base64 = base64_encode($this->hexToStr($str));
return openssl_decrypt($base64, 'des-ecb', $key);
}
上述方法是des的解密,请问一下加密该如何操作,能够让加密出来的结果,通过desDecrypt可以解密出来。试了好久没有搞出来
$test = openssl_encrypt($string, 'des-ecb', $key, 0);
var_dump(bin2hex(base64_decode($test)));
写了如上的加密,貌似是可以了,就是不知道对不对
没有加密的代码,当然就不能加密咯!
下面是我补充完整后的代码: