加密
function encode($str,$key) { $res = base64_encode($str); $code = $res^$key; return $code; }
解密
function decode($str,$key) { return base64_decode($str^$key); }
完整程式碼範例:
$str = '111021'; $key = 'APPYJJ-PHONE-LAZY'; function encode($str,$key) { $res = base64_encode($str); $code = $res^$key; return $code; } $str = encode($str,$key); print_r($str); echo "<hr>"; function decode($str,$key) { return base64_decode($str^$key); } print_r(decode($str,$key));
//加密的时候; $a = $str >> 4; //解密的时候则相反 $a = $str << 4;
完整程式碼範例:
function encode($str,$key) { $res = base64_encode($str); $code = $res^$key; return $code; }
function decode($str,$key) { return base64_decode($str^$key); }
base64加密後異或字串加密方式
加密$str = '111021'; $key = 'APPYJJ-PHONE-LAZY'; function encode($str,$key) { $res = base64_encode($str); $code = $res^$key; return $code; } $str = encode($str,$key); print_r($str); echo "<hr>"; function decode($str,$key) { return base64_decode($str^$key); } print_r(decode($str,$key));登入後複製登入後複製
解密
//加密的时候; $a = $str >> 4; //解密的时候则相反 $a = $str << 4;
如果感覺還是不安全的話。那我就在此拋磚引玉了;建議大家可以繼續在加密解密過程中運用移位運算
更多分享一個剛寫的PHP加密解密函數相關文章請關注PHP中文網!