protected void initCipher() throws IOException, NoSuchAlgorithmException {
		// packet header with length,version,symalgo,s2kversion,hashalgo
		// 9 means AES256
		// 8 means SHA256
		byte[] b = { (byte) 0xC3, 13, 4, 9, 3, 8 };
		out.write(b);

		byte[] salt = new byte[8];
		random.nextBytes(salt);

		out.write(salt);

		/*
		 * #define EXPBIAS 6 count = ((Int32)16 + (c & 15)) << ((c >> 4) +
		 * EXPBIAS);
		 *
		 * precomputed: c=0x9F .... count=1015808
		 */
		out.write(0x9F);
		int count = 1015808;
		byte[] pw = pass.getBytes("UTF-8");
		int len = pw.length + 8;

		MessageDigest md = MessageDigest.getInstance("SHA-256");
		while (count > len) {
			md.update(salt, 0, 8);
			md.update(pw);
			count -= len;
		}

		if (count < 8) {
			md.update(salt, 0, count);
		} else {
			md.update(salt, 0, 8);
			count -= 8;
			md.update(pw, 0, count);
		}

		SecretKey secret = new SecretKeySpec(md.digest(), "AES");

		try {
			cipher = Cipher.getInstance("AES/CFB128/NoPadding");
		} catch (NoSuchPaddingException e) {
			// nopadding always exists
		}

		// iv is initialized to all 0x00 by default
		byte[] iv = new byte[16];
		IvParameterSpec ips = new IvParameterSpec(iv);

		try {
			cipher.init(Cipher.ENCRYPT_MODE, secret, ips);
		} catch (InvalidKeyException e) {
			// should never occur
			e.printStackTrace();
		} catch (InvalidAlgorithmParameterException e) {
			// params should be ok
			e.printStackTrace();
		}

		// AES has 128 bit blocksize: 16+2
		int bs = cipher.getBlockSize();
		byte[] ivrep = new byte[bs + 2];
		random.nextBytes(ivrep);
		ivrep[bs] = ivrep[bs - 2];
		ivrep[bs + 1] = ivrep[bs - 1];

		hash.update(ivrep, 0, bs + 2);
		try {
			pos = cipher.update(ivrep, 0, bs + 2, buf);
		} catch (ShortBufferException e) {
		}
		ciphpos = bs + 2;
	}