关于XOR加密的概念可以参考 阮一峰老师的博客:http://www.ruanyifeng.com/blog/2017/05/xor.html
下面给出代码实例
<?php
class XorEncrypt{
private static $key = 'XorEncryptKey';
private static $randomStrLen = 3;
public static function encrypt($message,$key = ''){
$key = $key == '' ? self::$key : $key;
$messageLen = strlen($message);
$cipherText = '';
$keyLen = strlen($key);
for($i=0;$i<=$messageLen;$i+=$keyLen){
$cipherText .= substr($message,$i,$keyLen) ^ $key;
}
//加入随机字符
$randomStr = self::generateRandomStr();
return base64_encode($randomStr.$cipherText);
}
public static function decrypt($cipherText,$key= ''){
$key = $key == '' ? self::$key : $key;
$cipherText = substr(base64_decode($cipherText),self::$randomStrLen);
$cipherTextLen =