在PHP 7中,可以使用openssl_encrypt
和openssl_decrypt
函数来进行DES加密和解密。
以下是一个使用DES加密的示例:
function encrypt($data, $key) {
$cipher = "DES-ECB";
$options = OPENSSL_RAW_DATA;
$encrypted = openssl_encrypt($data, $cipher, $key, $options);
return base64_encode($encrypted);
}
function decrypt($encrypted, $key) {
$cipher = "DES-ECB";
$options = OPENSSL_RAW_DATA;
$decrypted = openssl_decrypt(base64_decode($encrypted), $cipher, $key, $options);
return $decrypted;
}
$data = "Hello World";
$key = "YourSecretKey";
$encryptedData = encrypt($data, $key);
echo "Encrypted Data: " . $encryptedData . "\n";
$decryptedData = decrypt($encryptedData, $key);
echo "Decrypted Data: " . $decryptedData . "\n";
请注意,这只是一个简单的示例,实际使用时需要根据具体需求进行适当的错误处理和安全性考虑。
下一篇:php 转时间戳在线
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站