public int parseCryptInfo(RdpPacket_Localised data)
			throws RdesktopException {
		logger.debug("Secure.parseCryptInfo");
		int encryption_level = 0, random_length = 0, RSA_info_length = 0;
		int tag = 0, length = 0;
		int next_tag = 0, end = 0;
		int rc4_key_size = 0;

		rc4_key_size = data.getLittleEndian32(); // 1 = 40-Bit 2 = 128 Bit
		encryption_level = data.getLittleEndian32(); // 1 = low, 2 = medium,
		// 3 = high
		if (encryption_level == 0) { // no encryption
			return 0;
		}
		random_length = data.getLittleEndian32();
		RSA_info_length = data.getLittleEndian32();

		if (random_length != SEC_RANDOM_SIZE) {
			throw new RdesktopException("Wrong Size of Random! Got"
					+ random_length + "expected" + SEC_RANDOM_SIZE);
		}
		this.server_random = new byte[random_length];
		data.copyToByteArray(this.server_random, 0, data.getPosition(),
				random_length);
		data.incrementPosition(random_length);

		end = data.getPosition() + RSA_info_length;

		if (end > data.getEnd()) {
			logger.debug("Reached end of crypt info prematurely ");
			return 0;
		}

		// data.incrementPosition(12); // unknown bytes
		int flags = data.getLittleEndian32(); // in_uint32_le(s, flags); // 1
		// = RDP4-style, 0x80000002 =
		// X.509
		logger.debug("Flags = 0x" + Integer.toHexString(flags));
		if ((flags & 1) != 0) {
			logger.debug(("We're going for the RDP4-style encryption"));
			data.incrementPosition(8); // in_uint8s(s, 8); // unknown

			while (data.getPosition() < data.getEnd()) {
				tag = data.getLittleEndian16();
				length = data.getLittleEndian16();

				next_tag = data.getPosition() + length;

				switch (tag) {

				case (Secure.SEC_TAG_PUBKEY):

					if (!parsePublicKey(data)) {
						return 0;
					}

					break;
				case (Secure.SEC_TAG_KEYSIG):
					// Microsoft issued a key but we don't care
					break;

				default:
					throw new RdesktopException("Unimplemented decrypt tag "
							+ tag);
				}
				data.setPosition(next_tag);
			}

			if (data.getPosition() == data.getEnd()) {
				return rc4_key_size;
			} else {
				logger.warn("End not reached!");
				return 0;
			}

		} else {
			// data.incrementPosition(4); // number of certificates
			int num_certs = data.getLittleEndian32();

			int cacert_len = data.getLittleEndian32();
			data.incrementPosition(cacert_len);
			int cert_len = data.getLittleEndian32();
			data.incrementPosition(cert_len);

			readCert = true;

			return rc4_key_size;
		}

	}