if (doc != null) {
KeyGenerator keygen = KeyGenerator.getInstance("AES");
keygen.init(new SecureRandom());
Key key = keygen.generateKey();
Encryption enc = security.getEncryption();
EncryptionOptions options = enc.getDefaultEncryptionOptions();
options.setDataEncryptionKey(key);
options.setKeyEncryptionKey(pkey);
options.setKeyCipherAlgorithm(XMLCipher.RSA_v1dot5);
options.setIncludeKeyInfo(true);
Document<Element> enc_doc = enc.encrypt(doc, options);
enc_doc.writeTo(response.getOutputStream());
}
} else {
chain.doFilter(request, response);