forked from summer9011/CustomLib
/
aes.php
33 lines (24 loc) · 806 Bytes
/
aes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
header("Content-type: text/html; charset=utf-8");
class AES {
private static $key = "set_key_here";
private static $iv = "setup_gIv_here11";
public static function encrypt($string) {
$encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, self::$key, $string, MCRYPT_MODE_CBC, self::$iv);
return base64_encode($encrypted);
}
public static function decrypt($string) {
$encryptedData = base64_decode($string);
$decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, self::$key, $encryptedData, MCRYPT_MODE_CBC, self::$iv);
return $decrypted;
}
}
if(isset($_GET['data'])) {
//解密客户端数据
$decode_str = AES::decrypt($_GET['data']);
//处理客户端数据
$decode_str = trim($decode_str)." append another data";
//返回处理结果
echo AES::encrypt($decode_str);
}
?>