"xmlns:" + WSConstants.ENC_PREFIX,
WSConstants.ENC_NS);
SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(envelope);
XMLCipher xmlCipher = null;
try {
xmlCipher = XMLCipher.getInstance(symEncAlgo);
} catch (XMLEncryptionException e3) {
throw new WSSecurityException(WSSecurityException.UNSUPPORTED_ALGORITHM, null, null, e3);
}
// if no encryption parts set - use the default
if (parts == null) {
parts = new Vector();
WSEncryptionPart encP =
new WSEncryptionPart(soapConstants.getBodyQName().getLocalPart(),
soapConstants.getEnvelopeURI(),
"Content");
parts.add(encP);
}
Vector encDataRefs = new Vector();
for (int part = 0; part < parts.size(); part++) {
WSEncryptionPart encPart = (WSEncryptionPart) parts.get(part);
String elemName = encPart.getName();
String nmSpace = encPart.getNamespace();
String modifier = encPart.getEncModifier();
/*
* Third step: get the data to encrypt.
*/
Element body =
(Element) WSSecurityUtil.findElement(envelope,
elemName,
nmSpace);
if (body == null) {
throw new WSSecurityException(WSSecurityException.FAILURE,
"noEncElement",
new Object[]{"{" + nmSpace + "}" + elemName});
}
boolean content = modifier.equals("Content") ? true : false;
String xencEncryptedDataId = "EncDataId-" + body.hashCode();
/*
* Forth step: encrypt data, and set neccessary attributes in
* xenc:EncryptedData
*/
try {
xmlCipher.init(XMLCipher.ENCRYPT_MODE, encryptionKey);
EncryptedData encData = xmlCipher.getEncryptedData();
encData.setId(xencEncryptedDataId);
encData.setKeyInfo(keyInfo);
xmlCipher.doFinal(doc, body, content);
} catch (Exception e2) {
throw new WSSecurityException(WSSecurityException.FAILED_ENC_DEC, null, null, e2);
}
encDataRefs.add(new String("#" + xencEncryptedDataId));
}