@Override
	public void write(byte[] b, int off, int len) throws IOException {
		hash.update(b, off, len);
		while (len > 0) {
			int tlen = Math.min(len, BUFFERSIZE - ciphpos);
			try {
				pos += cipher.update(b, off, tlen, buf, pos);
			} catch (ShortBufferException e) {
			}
			ciphpos += tlen;
			len -= tlen;
			off += tlen;

			if (pos == BUFFERSIZE) {
				out.write(PARTIAL_BUFFERSIZE);
				out.write(version);
				out.write(buf, 0, BUFFERSIZE - 1);
				version = buf[BUFFERSIZE - 1];
				pos = 0;
				ciphpos = 0;
			}
		}
	}