bnbweb/includes/lib_crypt.php
2022-11-14 23:49:28 +08:00

55 lines
1.1 KiB
PHP
Executable File

<?php
function aesDecrypt($encryptedData) {
$cipher = MCRYPT_RIJNDAEL_128;
$mode = MCRYPT_MODE_CBC;
$key = "WGI@X9ENgpo138jL";
$iv = "m%2qQ7L&wfafUj&b";
$initializationVectorSize = mcrypt_get_iv_size($cipher, $mode);
@$data = mcrypt_decrypt(
$cipher,
$key,
base64_decode($encryptedData),
$mode,
$iv
);
$pad = ord($data[strlen($data) - 1]);
return substr($data, 0, -$pad);
}
// 加密
function getAesEncrypt($xml_data) {
$cipher = MCRYPT_RIJNDAEL_128;
$mode = MCRYPT_MODE_CBC;
$key = "WGI@X9ENgpo138jL";
$iv = "m%2qQ7L&wfafUj&b";
@$blockSize = mcrypt_get_block_size($cipher, $mode);
$pad = $blockSize - (strlen($xml_data) % $blockSize);
return @base64_encode(mcrypt_encrypt(
$cipher,
$key,
$xml_data . str_repeat(chr($pad), $pad),
$mode,
$iv
));
}
class DES
{
var $key;
var $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 ));
}
}
?>