Title: [WSS4J 1.5] CryptoFactory: Cannot load properties: crypto.properties

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

Reply via email to