users@glassfish.java.net

Getting Exception error in generating XML digital signal

From: <glassfish_at_javadesktop.org>
Date: Tue, 11 Mar 2008 08:37:09 PST

Hello Everyone,

I'm trying to generate XML digital Signal. but I'm getting Exception error. This code is taken from internet. I'm just using this code.

public class GenerateSignature {
        public static void main(String[] args) throws Exception {
        String input = "invoice.xml ";
        String output = "signature.xml";
        if(args.length > 2) {
            input = args[0];
            output = args[1];
        }

        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);

        String providerName = System.getProperty("jsr105Provider", "org.jcp.XML.dsig.internal.dom.XMLDSigRI");
        XMLSignatureFactory fac = XMLSignatureFactory.getInstance("DOM",(Provider) Class.forName(providerName).newInstance());

        Reference ref = fac.newReference("#invoice", fac.newDigestMethod(DigestMethod.SHA1, null));

        Document XML = dbf.newDocumentBuilder().parse(new File(input));
        Node invoice = XML.getDocumentElement();
        XMLStructure content = new DOMStructure(invoice);
        XMLObject obj = fac.newXMLObject(Collections.singletonList(content), "invoice", null, null);

        SignedInfo si = fac.newSignedInfo(fac.newCanonicalizationMethod(
                       CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS,
                       (C14NMethodParameterSpec) null),
                       fac.newSignatureMethod(SignatureMethod.DSA_SHA1, null),
                       Collections.singletonList(ref));

        PrivateKey privateKey = null;
        KeyPair kp = KeyStoreInfo.getKeyPair("bizkeystore", "sp1234", "kp1234", "biz");
        KeyInfo ki = null;
        KeyInfoFactory kif = fac.getKeyInfoFactory();
        KeyValue kv = kif.newKeyValue(kp.getPublic());
            ki = kif.newKeyInfo(Collections.singletonList(kv));

        XMLSignature signature = fac.newXMLSignature(si, ki,
                Collections.singletonList(obj), null, null);

        Document doc = dbf.newDocumentBuilder().newDocument();
        DOMSignContext dsc = new DOMSignContext(privateKey, doc);

        signature.sign(dsc);

        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer trans = tf.newTransformer();
        trans.transform(new DOMSource(doc), new StreamResult(new FileOutputStream(output)));
    }
}

I'm getting the following error:

Exception in thread "main" java.lang.ClassNotFoundException: org.jcp.XML.dsig.internal.dom.XMLDSigRI
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:164)
        at src.GenerateSignature.main(GenerateSignature.java:49)

Please help me out there. It's very urgent...
[Message sent by forum member 'javastdnt' (javastdnt)]

http://forums.java.net/jive/thread.jspa?messageID=263382