goja-core/src/main/java/goja/core/libs/XML.java
public static Document sign(Document document, RSAPublicKey publicKey, RSAPrivateKey privateKey) {
        XMLSignatureFactory fac = XMLSignatureFactory.getInstance("DOM");
        KeyInfoFactory keyInfoFactory = fac.getKeyInfoFactory();

        try {
            Reference ref = fac.newReference(
                    "",
                    fac.newDigestMethod(DigestMethod.SHA1, null),
                    Collections.singletonList(
                            fac.newTransform(Transform.ENVELOPED, (TransformParameterSpec) null)),
                    null,
                    null);
            SignedInfo si =
                    fac.newSignedInfo(fac.newCanonicalizationMethod(CanonicalizationMethod.INCLUSIVE,
                            (C14NMethodParameterSpec) null),
                            fac.newSignatureMethod(SignatureMethod.RSA_SHA1, null),
                            Collections.singletonList(ref));
            DOMSignContext dsc = new DOMSignContext(privateKey, document.getDocumentElement());
            KeyValue keyValue = keyInfoFactory.newKeyValue(publicKey);
            KeyInfo ki = keyInfoFactory.newKeyInfo(Collections.singletonList(keyValue));
            XMLSignature signature = fac.newXMLSignature(si, ki);
            signature.sign(dsc);
        } catch (Exception e) {
            logger.warn("Error while signing an XML document.", e);
        }

        return document;
    }
public static Document sign(Document document, RSAPublicKey publicKey, RSAPrivateKey privateKey) {
        XMLSignatureFactory fac = XMLSignatureFactory.getInstance("DOM");
        KeyInfoFactory keyInfoFactory = fac.getKeyInfoFactory();

        try {
            Reference ref = fac.newReference(
                    "",
                    fac.newDigestMethod(DigestMethod.SHA1, null),
                    Collections.singletonList(
                            fac.newTransform(Transform.ENVELOPED, (TransformParameterSpec) null)),
                    null,
                    null);
            SignedInfo si =
                    fac.newSignedInfo(fac.newCanonicalizationMethod(CanonicalizationMethod.INCLUSIVE,
                            (C14NMethodParameterSpec) null),
                            fac.newSignatureMethod(SignatureMethod.RSA_SHA1, null),
                            Collections.singletonList(ref));
            DOMSignContext dsc = new DOMSignContext(privateKey, document.getDocumentElement());
            KeyValue keyValue = keyInfoFactory.newKeyValue(publicKey);
            KeyInfo ki = keyInfoFactory.newKeyInfo(Collections.singletonList(keyValue));
            XMLSignature signature = fac.newXMLSignature(si, ki);
            signature.sign(dsc);
        } catch (Exception e) {
            logger.warn("Error while signing an XML document.", e);
        }

        return document;
    }
public static Document sign ( Document document , RSAPublicKey publicKey , RSAPrivateKey privateKey ) { XMLSignatureFactory fac = XMLSignatureFactory . getInstance ( "DOM" ) ; KeyInfoFactory keyInfoFactory = fac . getKeyInfoFactory ( ) ; try { Reference ref = fac . newReference ( "" , fac . newDigestMethod ( DigestMethod . SHA1 , null ) , Collections . singletonList ( fac . newTransform ( Transform . ENVELOPED , ( TransformParameterSpec ) null ) ) , null , null ) ; SignedInfo si = fac . newSignedInfo ( fac . newCanonicalizationMethod ( CanonicalizationMethod . INCLUSIVE , ( C14NMethodParameterSpec ) null ) , fac . newSignatureMethod ( SignatureMethod . RSA_SHA1 , null ) , Collections . singletonList ( ref ) ) ; DOMSignContext dsc = new DOMSignContext ( privateKey , document . getDocumentElement ( ) ) ; KeyValue keyValue = keyInfoFactory . newKeyValue ( publicKey ) ; KeyInfo ki = keyInfoFactory . newKeyInfo ( Collections . singletonList ( keyValue ) ) ; XMLSignature signature = fac . newXMLSignature ( si , ki ) ; signature . sign ( dsc ) ; } catch ( Exception e ) { logger . warn ( "Error while signing an XML document." , e ) ; } return document ; }
Sign the XML document using xmldsig.

@param document   the document to sign; it will be modified by the method.
@param publicKey  the public key from the key pair to sign the document.
@param privateKey the private key from the key pair to sign the document.
@return the signed document for chaining.
Sign the XML document using xmldsig .