} public static function encrypt($str) { if (Urlcrypt::$key === "") { throw new Exception('No key provided.'); } $key = pack('H*', Urlcrypt::$key); $iv_size = mcrypt_get_iv_size(Urlcrypt::$cipher, Urlcrypt::$mode); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); $str = utf8_encode($str); $ciphertext = mcrypt_encrypt(Urlcrypt::$cipher, $key, $str, Urlcrypt::$mode, $iv); $ciphertext = $iv . $ciphertext; return Urlcrypt::encode($ciphertext); } public static function decrypt($str) { if (Urlcrypt::$key === "") { throw new Exception('No key provided.'); } $key = pack('H*', Urlcrypt::$key); $str = Urlcrypt::decode($str); $iv_size = mcrypt_get_iv_size(Urlcrypt::$cipher, Urlcrypt::$mode); $iv_dec = substr($str, 0, $iv_size); $str = substr($str, $iv_size); $str = mcrypt_decrypt(Urlcrypt::$cipher, $key, $str, Urlcrypt::$mode, $iv_dec); // http://jonathonhill.net/2013-04-05/write-tests-you-might-learn-somethin/ return rtrim($str, ""); } } Urlcrypt::$table = str_split(Urlcrypt::$table, 1);