ret.setPreferredDigestAlg(req.getPreferredDigestAlg());
    private IResponseMessage createResponseMessage(Class responseClass, IRequestMessage req, CA ca, CAToken catoken) throws CATokenOfflineException {    	IResponseMessage ret = null;    	// Create the response message and set all required fields    	try {    		ret = (IResponseMessage) responseClass.newInstance();    	} catch (InstantiationException e) {    		//TODO : do something with these exceptions    		log.error("Error creating response message", e);    		return null;    	} catch (IllegalAccessException e) {    		log.error("Error creating response message", e);    		return null;    	}    	if (ret.requireSignKeyInfo()) {    		ret.setSignKeyInfo((X509Certificate) ca.getCACertificate(), catoken.getPrivateKey(SecConst.CAKEYPURPOSE_CERTSIGN));    	}    	if (ret.requireEncKeyInfo()) {    		ret.setEncKeyInfo((X509Certificate) ca.getCACertificate(), catoken.getPrivateKey(SecConst.CAKEYPURPOSE_KEYENCRYPT));    	}    	if (req.getSenderNonce() != null) {    		ret.setRecipientNonce(req.getSenderNonce());    	}    	if (req.getTransactionId() != null) {    		ret.setTransactionId(req.getTransactionId());    	}    	// Sendernonce is a random number    	byte[] senderNonce = new byte[16];    	randomSource.nextBytes(senderNonce);    	ret.setSenderNonce(new String(Base64.encode(senderNonce)));    	// If we have a specified request key info, use it in the reply    	if (req.getRequestKeyInfo() != null) {    		ret.setRecipientKeyInfo(req.getRequestKeyInfo());    	}    	return ret;    }