private byte[] unwrapResponseAPDU(byte[] rapdu, int len)
			throws GeneralSecurityException, IOException {
		long oldssc = ssc;
		try {
			if (rapdu == null || rapdu.length < 2 || len < 2) {
				throw new IllegalArgumentException("Invalid response APDU");
			}
			cipher.init(Cipher.DECRYPT_MODE, ksEnc, ZERO_IV_PARAM_SPEC);
			DataInputStream in = new DataInputStream(new ByteArrayInputStream(rapdu));
			byte[] data = new byte[0];
			short sw = 0;
			boolean finished = false;
			byte[] cc = null;
			while (!finished) {
				int tag = in.readByte();
				switch (tag) {
					case (byte) 0x87:
						data = readDO87(in);
						break;
					case (byte) 0x99:
						sw = readDO99(in);
						break;
					case (byte) 0x8E:
						cc = readDO8E(in);
						finished = true;
						break;
				}
			}
			if (!checkMac(rapdu, cc)) {
				throw new IllegalStateException("Invalid MAC");
			}
			ByteArrayOutputStream out = new ByteArrayOutputStream();
			out.write(data, 0, data.length);
			out.write((sw & 0x0000FF00) >> 8);
			out.write(sw & 0x000000FF);
			return out.toByteArray();
		} finally {
			/*
			 * If we fail to unwrap, at least make sure we have
			 * the same counter as the ICC, so that we can continue
			 * to communicate using secure messaging...
			 */
			if (ssc == oldssc) {
				ssc++;
			}
		}
	}