<?php
namespace App\Utilities;
class DES
{
public $key;
public $iv;
function __construct($key, $iv = 0)
{
$this->key = $key;
if ($iv == 0) {
$this->iv = $key;
} else {
$this->iv = $iv;
}
}
function encrypt($str)
{
return base64_encode(openssl_encrypt($str, 'DES-CBC', $this->key, OPENSSL_RAW_DATA, $this->iv));
}
function decrypt($str) {
$str = openssl_decrypt(base64_decode($str), 'DES-CBC', $this->key, OPENSSL_RAW_DATA | OPENSSL_NO_PADDING, $this->iv);
return rtrim($str, "\x1\x2\x3\x4\x5\x6\x7\x8");
}
}
$res = "MDQGx7yYdmYEDXNWr5rzDvsvT3eVG91rvnkdDZi8y2Y%3D";
$crypt = new DES($key);
var_dump($crypt->decrypt(urldecode($res)));
?>
PHP 版本 DES 加解密
最新推荐文章于 2025-04-27 11:08:22 发布