PHP7.2用Openssl替换merypt加解密

用的3des加密

merypt加密:

$message = mcrypt_encrypt(MCRYPT_3DES,"key",$content,MCRYPT_MODE_ECB,$iv);
return bin2hex($message);

merypt解密:

$td = crypt_module_open(MCRYPT_3DES,'',MCRYPT_MODE_ECB,'');
mcrypt_generic_init($td,'key',$iv);
$dencrypt = mdecrypt_generic($td,$message);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return $dencrypt;

Openssl加密:

$message = openssl_encrypt($content,"DES-EDE3","key",OPENSSL_RAW_DATA|OPENSSL_NO_PADDING,$iv);
return bin2hex($message);

Openssl解密:

$dencrypt = openssl_decrypt($message,"DES-EDE3","key",OPENSSL_RAW_DATA|OPENSSL_NO_PADDING,$iv);
//去除补位字符
return $dencrypt;

您可能还喜欢...

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注