Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Web Services and the fly likes .net Webservice Integration with Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark ".net Webservice Integration with Java" Watch ".net Webservice Integration with Java" New topic
Author

.net Webservice Integration with Java

anubechara Gupta
Greenhorn

Joined: Jul 05, 2006
Posts: 17
Hello Ranchers
I am trying to consume .net Webservice by making java client. The service is using WSSE security standards. We have to encrypt the body contents of Soap message with the help og User Name Security token.I am using WSS4J for doing this but the .net is not able to decrypt the data. Seeems like our keys are different, The AES256 algorithm has to be used for encryption of messages and key should be combination of password+nonce+createdtimestamp. I am attaching the java code which I am using to encrypt the message. Please suggest what mistake I am making. I will be very thankful.

public static void addEncryption(WSSecHeader wsSecHeader, WSSecUsernameToken token, Document soapDoc, SecretKey key)
throws Exception
{
Reference reference;
try
{
reference = new Reference(soapDoc);
reference.setURI("#" + token.getId());
reference.setValueType("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#UsernameToken");

SecurityTokenReference securityTokenReference = new SecurityTokenReference(soapDoc);

securityTokenReference.setReference(reference);

WSSecurityUtil.setNamespace(securityTokenReference.getElement(), "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "wsse");

WSSecEncrypt secEncrypt = new WSSecEncrypt();

secEncrypt.setKeyIdentifierType(6);

secEncrypt.setSecurityTokenReference(securityTokenReference);
secEncrypt.setSymmetricEncAlgorithm("http://www.w3.org/2001/04/xmlenc#aes256-cbc");
secEncrypt.setKey(token.getSecretKey());
//secEncrypt.setKey(key.getEncoded());

secEncrypt.setDocument(soapDoc);

SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(soapDoc.getDocumentElement());

Vector parts = new Vector();
WSEncryptionPart encP = new WSEncryptionPart(soapConstants.getBodyQName().getLocalPart(), soapConstants.getEnvelopeURI(), "Content");

parts.add(encP);

//secEncrypt.setParts(parts);

secEncrypt.build(soapDoc, null, wsSecHeader);
}
catch (WSSecurityException wsEx) {
wsEx.printStackTrace();
throw new Exception("Unable to encrypt the message parts");
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: .net Webservice Integration with Java