2012. 1. 9. 19:17

mcrypt 암호화 모듈

/** * encrypt, decrypt 관련 함수 * * @author Yongseok Kang <wyseburn(at)gmail.com> * @since 2011. 7. 13. * @category * @version 1.0 */ define('ENC_KEY', 'enckey!@#$'); //키 값 /** * hex2bin * @param string $hexdata */ function hex2bin($hexdata) { $bindata=""; for ($i=0,$cnt=strlen($hexdata);$i<$cnt;$i+=2) { $bindata .= chr(hexdec(substr($hexdata,$i,2))); } return $bindata; } /** * 키를 통해 암호화 * @param string $str */ function m_encrypt($str) { return bin2hex(gzcompress(mcrypt_ecb(MCRYPT_RIJNDAEL_192, md5(ENC_KEY), $str, MCRYPT_ENCRYPT))); } /** * 키를 통해 복호화 * @param string $str */ function m_decrypt($str) { return trim(mcrypt_ecb(MCRYPT_RIJNDAEL_192, md5(ENC_KEY), gzuncompress(hex2bin($str)), MCRYPT_DECRYPT)); }