*
* @throws Exception Thrown when there is any problem in signing or verification
*/
public void testEncryptionDecryptionRSA15() throws Exception {
SOAPEnvelope unsignedEnvelope = message.getSOAPEnvelope();
WSSecEncrypt builder = new WSSecEncrypt();
builder.setUserInfo("wss4jcert");
builder.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
builder.setSymmetricEncAlgorithm(WSConstants.TRIPLE_DES);
Document doc = unsignedEnvelope.getAsDocument();
WSSecHeader secHeader = new WSSecHeader();
secHeader.insertSecurityHeader(doc);
LOG.info("Before Encryption Triple DES....");
Document encryptedDoc = builder.build(doc, crypto, secHeader);
LOG.info("After Encryption Triple DES....");
String outputString =
org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(encryptedDoc);
if (LOG.isDebugEnabled()) {
LOG.debug("Encrypted message, RSA-15 keytransport, 3DES:");
LOG.debug(outputString);
}
assertTrue(outputString.indexOf("LogTestService2") == -1 ? true : false);
verify(encryptedDoc, SOAP_BODY);
/*
* second run, same Junit set up, but change encryption method,
* key identification, encryption mode (Element now), and data to encrypt.
* This tests if several runs of different algorithms on same builder/cipher
* setup are ok.
*/
message = getSOAPMessage(); // create fresh message environment
builder.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
builder.setSymmetricEncAlgorithm(WSConstants.AES_128);
Vector parts = new Vector();
WSEncryptionPart encP =
new WSEncryptionPart("testMethod", "uri:LogTestService2", "Element");
parts.add(encP);
builder.setParts(parts);
unsignedEnvelope = message.getSOAPEnvelope();
doc = unsignedEnvelope.getAsDocument();
secHeader = new WSSecHeader();
secHeader.insertSecurityHeader(doc);
LOG.info("Before Encryption AES 128/RSA-15....");
encryptedDoc = builder.build(doc, crypto, secHeader);
LOG.info("After Encryption AES 128/RSA-15....");
outputString =
org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(encryptedDoc);
if (LOG.isDebugEnabled()) {
LOG.debug("Encrypted message, RSA-15 keytransport, AES 128:");