// Path: animamea/src/de/tsenger/animamea/crypto/AmCryptoException.java
// @SuppressWarnings("serial")
// public class AmCryptoException extends Exception {
// 
// 	/**
// 	 * 
// 	 */
// 	public AmCryptoException() {
// 		// TODO Auto-generated constructor stub
// 	}
// 
// 	/**
// 	 * @param message
// 	 */
// 	public AmCryptoException(String message) {
// 		super(message);
// 		// TODO Auto-generated constructor stub
// 	}
// 
// 	/**
// 	 * @param cause
// 	 */
// 	public AmCryptoException(Throwable cause) {
// 		super(cause);
// 		// TODO Auto-generated constructor stub
// 	}
// 
// 	/**
// 	 * @param message
// 	 * @param cause
// 	 */
// 	public AmCryptoException(String message, Throwable cause) {
// 		super(message, cause);
// 		// TODO Auto-generated constructor stub
// 	}
// 
// }


import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.smartcardio.CommandAPDU;
import javax.smartcardio.ResponseAPDU;
import org.bouncycastle.asn1.ASN1InputStream;
import de.tsenger.animamea.crypto.AmCryptoException;
import de.tsenger.animamea.crypto.AmCryptoProvider;
import de.tsenger.animamea.tools.HexString;
		// occurs

		// Construct K (SSC||DO87||DO99)
		ByteArrayOutputStream bout = new ByteArrayOutputStream();
		try {
			if (do87 != null)
				bout.write(do87.getEncoded());
			bout.write(do99.getEncoded());
		} catch (IOException e) {
			throw new SecureMessagingException(e);
		}

		crypto.init(ks_mac, ssc);
		byte[] cc = crypto.getMAC(bout.toByteArray());

		byte[] do8eData = do8E.getData();

		if (!java.util.Arrays.equals(cc, do8eData))
			throw new SecureMessagingException("Checksum is incorrect!\n Calculated CC: " + HexString.bufferToHex(cc) + "\nCC in DO8E: "
					+ HexString.bufferToHex(do8eData));

		// Decrypt DO87
		byte[] data = null;
		byte[] unwrappedAPDUBytes = null;

		if (do87 != null) {
			crypto.init(ks_enc, ssc);
			byte[] do87Data = do87.getData();
			try {
				data = crypto.decrypt(do87Data);
// Path: animamea/src/de/tsenger/animamea/crypto/AmCryptoException.java
// @SuppressWarnings("serial")
// public class AmCryptoException extends Exception {
// 
// 	/**
// 	 * 
// 	 */
// 	public AmCryptoException() {
// 		// TODO Auto-generated constructor stub
// 	}
// 
// 	/**
// 	 * @param message
// 	 */
// 	public AmCryptoException(String message) {
// 		super(message);
// 		// TODO Auto-generated constructor stub
// 	}
// 
// 	/**
// 	 * @param cause
// 	 */
// 	public AmCryptoException(Throwable cause) {
// 		super(cause);
// 		// TODO Auto-generated constructor stub
// 	}
// 
// 	/**
// 	 * @param message
// 	 * @param cause
// 	 */
// 	public AmCryptoException(String message, Throwable cause) {
// 		super(message, cause);
// 		// TODO Auto-generated constructor stub
// 	}
// 
// }


// Path: animamea/src/de/tsenger/animamea/iso7816/SecureMessaging.java
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.smartcardio.CommandAPDU;
import javax.smartcardio.ResponseAPDU;
import org.bouncycastle.asn1.ASN1InputStream;
import de.tsenger.animamea.crypto.AmCryptoException;
import de.tsenger.animamea.crypto.AmCryptoProvider;
import de.tsenger.animamea.tools.HexString;

		// occurs

		// Construct K (SSC||DO87||DO99)
		ByteArrayOutputStream bout = new ByteArrayOutputStream();
		try {
			if (do87 != null)
				bout.write(do87.getEncoded());
			bout.write(do99.getEncoded());
		} catch (IOException e) {
			throw new SecureMessagingException(e);
		}

		crypto.init(ks_mac, ssc);
		byte[] cc = crypto.getMAC(bout.toByteArray());

		byte[] do8eData = do8E.getData();

		if (!java.util.Arrays.equals(cc, do8eData))
			throw new SecureMessagingException("Checksum is incorrect!\n Calculated CC: " + HexString.bufferToHex(cc) + "\nCC in DO8E: "
					+ HexString.bufferToHex(do8eData));

		// Decrypt DO87
		byte[] data = null;
		byte[] unwrappedAPDUBytes = null;

		if (do87 != null) {
			crypto.init(ks_enc, ssc);
			byte[] do87Data = do87.getData();
			try {
				data = crypto.decrypt(do87Data);
			} catch (AmCryptoException e) {