PHP7.1以后,移除了mcrypt扩展,用openssl替代。
常见的几种3des加密方法:
<?php
namespace App\Http\Lib;
class Helpers
{
// 3des,非标准(某些平台会用),全转了十六进制
public static function en3des($string, $key)
{
return bin2hex(openssl_encrypt($string, 'DES-EDE3', $key, OPENSSL_RAW_DATA));
}
public static function de3des($string,$key)
{
return openssl_decrypt(pack('H*',$string), 'DES-EDE3', $key, OPENSSL_RAW_DATA);
}
// 正宗的3des加密
public static function en3des_base64($string,$key)
{
return base64_encode(openssl_encrypt($string, 'DES-EDE3', $key, OPENSSL_RAW_DATA));
}
public static function de3des_base64($string,$key)
{
return openssl_decrypt(base64_decode($string), 'DES-EDE3', $key, OPENSSL_RAW_DATA);
}
}
网友评论