public boolean processDataOut(APDU apdu) {
		if (selectingApplet())
			return false; //allow other Services to postprocess if needed
		if (mode == ENCRYPT_NONE) {
			return false;
		}
		if (mode == SYMMETRIC_REQUEST) {
			mode = ENCRYPT_SYMMETRIC;
			return false;
		}
		if(mode == ASYMMETRIC_REQUEST) {
			mode = ENCRYPT_ASYMMETRIC;
			return false;
		}
        // byte[]  buffer = null;
        // byte[]  padded = null;
        // byte[]  buff = null;
		// get outgoing APDU buffer (CLA,INS,SW1,SW2,Le,data field)
		// byte[] buffer = apdu.getBuffer();
        // byte[] originalbuffer = apdu.getBuffer();
                    // adds hash and modifies le to fit hash
            // buffer = Authenticator.appendHash(originalbuffer);
            // byte le = originalbuffer[OFFSET_OUT_LA];
            // byte leplusone = (byte)((short)(le+1));
            // buffer[OFFSET_OUT_LA] = leplusone;
            
            // encrypt the data field in response APDU
            // byte unpaddedLength = (byte) (buffer[OFFSET_OUT_LA] & 0xFF);
            // pad the buffer segment to have blocks of length BLOCK_SIZE
            // bytes as per PKCS#5 padding scheme where the padding bytes
            // always each give the number of padded bytes
            // short numBlocks = (short) ((short) (unpaddedLength + BLOCK_SIZE) / BLOCK_SIZE);
            // short paddedLength = (short) (numBlocks * BLOCK_SIZE);
            // padded = getTransientArray(paddedLength);
            // Util.arrayCopyNonAtomic(buffer, OFFSET_OUT_RDATA, padded, (short) 0, unpaddedLength);
            // byte numPadding = (byte) (paddedLength - unpaddedLength);
            // for (short i = unpaddedLength; i < paddedLength; i++){
                // padded[i] = numPadding;
            // }
            // if ((short) (OFFSET_OUT_RDATA - 1 + paddedLength) > buffer.length) { // outgoing buffer can not accommodate the padding
                // CryptoException.throwIt(CryptoException.ILLEGAL_VALUE);
            // }
            // if(mode == ENCRYPT_SYMMETRIC) {
                // encryptCipher.init(key, Cipher.MODE_ENCRYPT, KeySpec.SESSION_IV_BYTES, (short) 0, (short) KeySpec.SESSION_IV_BYTES.length);
            // } else if(mode == ENCRYPT_ASYMMETRIC) {
                // encryptCipher.init(privateKey, Cipher.MODE_ENCRYPT);
            // } else {
                // ISOException.throwIt(ISO7816.SW_WRONG_DATA);
            // }
            // ISOException.throwIt(ISO7816.SW_WRONG_DATA);
            // buff = getTransientArray((short)(paddedLength+OFFSET_OUT_RDATA));
            // buff[0] = buffer[0];
            // buff[1] = buffer[1];
            // buff[2] = buffer[2];
            // buff[3] = buffer[3];
            // buff[OFFSET_OUT_LA] = (byte) paddedLength;
            
            // encryptCipher.doFinal(padded, (short) 0, paddedLength, buff, OFFSET_OUT_RDATA);
            // Util.arrayCopyNonAtomic(padded, (short) 0, buff, OFFSET_OUT_RDATA, (short)(paddedLength));
            // Util.arrayCopyNonAtomic(buff, (short) 0, originalbuffer, (short) 0, (short)(paddedLength+OFFSET_OUT_RDATA));
            
            // return true;
            
        // get outgoing APDU buffer (CLA,INS,SW1,SW2,Le,data field)
		byte[] buffer = apdu.getBuffer();

		// encrypt the data field in response APDU
		byte unpaddedLength = (byte) (buffer[OFFSET_OUT_LA] & 0xFF);
		// pad the buffer segment to have blocks of length BLOCK_SIZE
		// bytes as per PKCS#5 padding scheme where the padding bytes
		// always each give the number of padded bytes
		short numBlocks = (short) ((short) (unpaddedLength + BLOCK_SIZE)
				/ BLOCK_SIZE);
		short paddedLength = (short) (numBlocks * BLOCK_SIZE);
		byte[] padded = getTransientArray(paddedLength);
		Util.arrayCopyNonAtomic(buffer, OFFSET_OUT_RDATA, padded, (short) 0, unpaddedLength);
		byte numPadding = (byte) (paddedLength - unpaddedLength);
		for (short i = unpaddedLength; i < paddedLength; i++)
			padded[i] = numPadding;
		if ((short) (OFFSET_OUT_RDATA - 1 + paddedLength) >
				buffer.length) { // outgoing buffer can not accommodate the padding
			CryptoException.throwIt(CryptoException.ILLEGAL_VALUE);
		}
		if(mode == ENCRYPT_SYMMETRIC) {
			encryptCipher.init(key, Cipher.MODE_ENCRYPT, KeySpec.SESSION_IV_BYTES, (short) 0,
					(short) KeySpec.SESSION_IV_BYTES.length);
		} else if(mode == ENCRYPT_ASYMMETRIC) {
			encryptCipher.init(privateKey, Cipher.MODE_ENCRYPT);
		} else {
			ISOException.throwIt(ISO7816.SW_WRONG_DATA);
		}
		encryptCipher.doFinal(padded, (short) 0, paddedLength, buffer, OFFSET_OUT_RDATA);
		buffer[OFFSET_OUT_LA] = (byte) paddedLength;
        
		return true; // don't allow any other postprocessing
	}