PHP gzdeflate+str_to13+pack的一种加密解密代码方式
首先我们要加密的明文是: $test=<<<'EVE' echo '<script>alert("nihao")</script>';die; EVE; 字符串转16进制,16进制还原的方法 function String2Hex($string){ $hex=''; for ($i=0; $i < strlen($string); $i++){ $hex .= dechex(ord($string[$i])); } return $hex; } function Hex2String($hex){ $string=''; for ($i=0; $i < strlen($hex)-1; $i+=2){ $string .= chr(hexdec($hex[$i].$hex[$i+1])); } return $string; } 加密: $test1= gzdeflate($test); #压缩$test1=base64_encode($test1); #转码$adam=String2Hex(str_rot13($test1)); #rot13+16进制转换 加密后的字符串: 463033426c537144676c794259666266585953596d527867586753446c66695a465a6b4b30654745756a64654a367178637962514e4e3d3d 解密: $ev=str_rot13(pack("H*",$adam)); $decoded=gzinflate(base64_decode($ev));