public function encode($id, $type = '')
{
if (!isset($this->_keys[$type])) {
$this->_keys[$type] = md5($this->_key . $type, true);
}
while (true) {
$rand = mt_rand() & 0xffff0000;
$r = base64_encode(mcrypt_encrypt(MCRYPT_XTEA, $this->_keys[$type], pack('VV', $id, $rand), MCRYPT_MODE_ECB));
if (strcspn($r, '+/') === 12) {
return substr($r, 0, -1);
}
}
return $id;
}