SecurityConstants.ENCRYPT_CRYPTO,
SecurityConstants.ENCRYPT_PROPERTIES);
userName = SecurityUtils.getUserName(crypto, userName);
if (StringUtils.isEmpty(userName)) {
throw new WSSecurityException("User name is not available");
}
receiverCert = getReceiverCertificateFromCrypto(crypto, userName);
}
if (receiverCert == null) {
throw new WSSecurityException("Receiver certificate is not available");
}
String keyEncAlgo = encProps.getEncryptionKeyTransportAlgo() == null
? XMLCipher.RSA_OAEP : encProps.getEncryptionKeyTransportAlgo();
String digestAlgo = encProps.getEncryptionDigestAlgo();
byte[] encryptedSecretKey = encryptSymmetricKey(secretKey, receiverCert,
keyEncAlgo, digestAlgo);
addEncryptedKeyElement(encryptedDataElement, receiverCert, encryptedSecretKey,
keyEncAlgo, digestAlgo);
}
// encrypt payloadDoc
XMLCipher xmlCipher =
EncryptionUtils.initXMLCipher(symEncAlgo, XMLCipher.ENCRYPT_MODE, symmetricKey);
Document result = xmlCipher.doFinal(payloadDoc, payloadDoc.getDocumentElement(), false);
NodeList list = result.getElementsByTagNameNS(WSConstants.ENC_NS, "CipherValue");
if (list.getLength() != 1) {
throw new WSSecurityException("Payload CipherData is missing", null);
}
String cipherText = ((Element)list.item(0)).getTextContent().trim();
Element cipherValue =
createCipherValue(encryptedDataDoc, encryptedDataDoc.getDocumentElement());
cipherValue.appendChild(encryptedDataDoc.createTextNode(cipherText));