WSSecEncryptedKey encryptedKey) throws TrustException {
XMLCipher xmlCipher = null;
SecretKey secretKey = null;
String xencEncryptedDataId = null;
KeyInfo keyInfo = null;
EncryptedData encData = null;
try {
xmlCipher = XMLCipher.getInstance(WSConstants.AES_256);
secretKey = WSSecurityUtil.prepareSecretKey(WSConstants.AES_256, encryptedKey
.getEphemeralKey());
xmlCipher.init(XMLCipher.ENCRYPT_MODE, secretKey);
xencEncryptedDataId = "EncDataId-" + assertionElement.hashCode();
keyInfo = new KeyInfo(doc);
keyInfo.addUnknownElement(encryptedKey.getEncryptedKeyElement());
encData = xmlCipher.getEncryptedData();
encData.setId(xencEncryptedDataId);
encData.setKeyInfo(keyInfo);
xmlCipher.doFinal(doc, assertionElement, false);
} catch (Exception e) {
throw new TrustException(TrustException.REQUEST_FAILED, e);
}
}