Hi Hermann,
First you have to have the crypto.properties file in the classpath
when you rung this program. Looking at the alias and password values
in your code seems like you are using this [1] PKCS12 keystore. You
can use this [2] crypto.properties file in you classpath if you make
the x509.PFX.MSFT
file from [1] available in a "keys" dir in the classpath.
Also to get your code working you will have to pass a WSSecHeader
instance to the build() method of WSSecSignature. The modified main()
method is available here [3].
Thanks,
Ruchith
[1] https://svn.apache.org/repos/asf/webservices/wss4j/trunk/keys/x509.PFX.MSFT
[2]
https://svn.apache.org/repos/asf/webservices/wss4j/trunk/src/crypto.properties
[3] http://rafb.net/paste/results/yoCbXV61.html
On 6/12/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
hi all
i have a probelm when i created a soap message that i want to sign.
the code is:
public class signer {
public static void main(String arg[]){
try{
Message signedSOAPMsg=null;
//Crea message factory
MessageFactory messageFactory =
MessageFactory.newInstance();
// Creazione di un messaggio
SOAPMessage message = messageFactory.createMessage();
SOAPEnvelope env= new SOAPEnvelope();
Message axisMessage = new Message(env,null);
SOAPEnvelope unsignedEnvelope =
axisMessage.getSOAPEnvelope();
Document doc = unsignedEnvelope.getAsDocument();
// WSSignEnvelope signs a SOAP envelope
according to the
// WS Specification (X509 profile) and adds the
signature data
// to the envelope.
WSSecSignature signer = new WSSecSignature();
String alias =
"16c73ab6-b892-458f-abf5-2f875f74882e";
String password = "security";
signer.setUserInfo(alias, password);
// create a vector of WSEncryptPart parts to
sign, both the soap body
//and the attachments
SOAPConstants soapConstants
=WSSecurityUtil.getSOAPConstants(unsignedEnvelope);
Vector parts = new Vector();
// add the body part
String localPart =
soapConstants.getBodyQName().getLocalPart();
String envelopeURI =
soapConstants.getEnvelopeURI();
WSEncryptionPart body = new
WSEncryptionPart(localPart, envelopeURI, "Content");
parts.add(body);
// how to add the attachment part?????
signer.setParts(parts);
// The "build" method, creates the signed SOAP
envelope.
// It takes a SOAP Envelope as a W3C Document
and adds
// a WSS Signature header to it. The signed
elements
// depend on the signature parts that are
specified by
// the WSBaseMessage.setParts(java.util.Vector
parts)
// method. By default, SOAP Body is signed.
// The "crypto" parameter is the object that
implements
// access to the keystore and handling of
certificates.
// A default implementation is included:
//
org.apache.ws.security.components.crypto.Merlin
Document signedDoc = signer.build(doc,
CryptoFactory.getInstance(),null);
// Convert the signed document into a SOAP
message.
signedSOAPMsg = (Message)
toSOAPMessage(signedDoc);
System.out.println(signedSOAPMsg);
} catch (Exception e) {
e.printStackTrace();
}
}
public static SOAPMessage toSOAPMessage(Document doc) throws
Exception {
Canonicalizer c14n
=Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS);
byte[] canonicalMessage = c14n.canonicalizeSubtree(doc);
ByteArrayInputStream in = new
ByteArrayInputStream(canonicalMessage);
MessageFactory factory = MessageFactory.newInstance();
return factory.createMessage(null, in);
}}
but when i compile there is this error:
java.lang.RuntimeException: CryptoFactory: Cannot load properties:
crypto.properties
at
org.apache.ws.security.components.crypto.CryptoFactory.getProperties(CryptoFactory.java:185)
at
org.apache.ws.security.components.crypto.CryptoFactory.getProperties(CryptoFactory.java:168)
at
org.apache.ws.security.components.crypto.CryptoFactory.getInstance(CryptoFactory.java:96)
at
org.apache.ws.security.components.crypto.CryptoFactory.getInstance(CryptoFactory.java:54)
at Perform.signer.main(signer.java:89)
How i can resolve this problem??
Thank you very much
Hermann
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]