public function encode($id, $type = '')
    {
        if (!isset($this->_keys[$type])) {
            if ($this->_key === null) {
                $this->_key = $this->crypt->getDerivedKey('secint');
            }

            $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;
    }