ÿØÿà JFIF ` ` ÿþ
Server : Apache System : Linux ruga7-004.fmcity.com 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64 User : tkt_travelbus ( 1137) PHP Version : 7.0.0p1 Disable Function : mysql_pconnect Directory : /tkt_travelbus/www/LibClass/ |
Upload File : |
<? class AES{ private static $secretKey = ''; private static $vector = ''; /** * * @param String $secretKey * @param String $vector */ function __construct($secretKey = '', $vector = '') { // secretKey, vector 가 존재하지 않다면 return false; if(!$secretKey || !$vector) { return false; }else{ self::$secretKey = $secretKey; self::$vector = $vector; } } /** * * @param string $string * @param int $blocksize Blocksize * @return String */ private function addPkcs7Padding($string, $blocksize = 16) { $len = strlen($string); $pad = $blocksize - ($len % $blocksize); $string .= str_repeat(chr($pad), $pad); return $string; } /** * * @param String * * @return String */ private function stripPkcs7Padding($string){ $slast = ord(substr($string, -1)); $slastc = chr($slast); $pcheck = substr($string, -$slast); if(preg_match("/$slastc{".$slast."}/", $string)){ $string = substr($string, 0, strlen($string)-$slast); return $string; } else { return false; } } private function decodeBytes($hex) { $str = ''; for($i=0;$i<strlen($hex);$i+=2){ $tmpValue = (((ord($hex[$i]) - ord('a')) & 0xf ) <<4) + ((ord($hex[$i+1])- ord('a')) & 0xf); $str .= chr($tmpValue); } return $str; } private function encodeBytes($string) { $str = ''; for($i=0;$i<strlen($string);$i++) { $tmpValue = ord($string[$i]); $ch = ($tmpValue >> 4 & 0xf) + ord('a'); $str .= chr($ch); $ch = ($tmpValue & 0xf) + ord('a'); $str .= chr($ch); } return $str; } /** * * @param String $encryptedText * @return String */ function decrypt($encryptedText) { $secretKey = self::$secretKey; $vector = self::$vector; $str = $this->decodeBytes($encryptedText); return $this->stripPkcs7Padding(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $secretKey, $str, MCRYPT_MODE_CBC, $vector)); } /** * * @param String $encryptedText * @return String */ function encrypt($decData) { $secretKey = self::$secretKey; $vector = self::$vector; if(is_array($decData)){ $decData = json_encode($decData); } $base = (mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $secretKey,$this->addPkcs7Padding($decData,16) , MCRYPT_MODE_CBC, $vector)); return $this->encodeBytes($base); } } ?>