XMLSignature newXMLSignature返回相同的实例

时间:2017-08-23 21:01:42

标签: java xml

我正试图为巴西人的财政笔记开发一个签名建设者。当我的系统签名两次在同一范围内分散xmls文件时,seconde在签名验证中失败。 我认为问题在于我的方法来构建签名。

public void build(Element elementToSign, Element parentElement, Certificate certificate, PrivateKey privateKey) {
        try {
            List<Reference> refList = newReferenceList(elementToSign);
            SignedInfo signedInfo = newSignedInfo(refList);
            KeyInfo keyInfo = keyInfoBuilder.newKeyInfo(certificate);
            DOMSignContext dsc = new DOMSignContext(privateKey, parentElement);
            XMLSignature signature = signatureFactory.newXMLSignature(signedInfo, keyInfo);
            logger.info("Assinatura: {}, keyInfo: {}, dsc: {}, signature: {}",
                    new Object[]{ signature, keyInfo, dsc, signature });
            signature.sign(dsc);
            logger.debug(" Primeiro digest value encontrado é {}.", ((Reference) signature.getSignedInfo().getReferences().get(0)).getDigestValue());
            InputStreamReader isr = 
                new InputStreamReader(signature.getSignedInfo().getCanonicalizedData());
            char[] cbuf = new char[1024];
            while (isr.read(cbuf, 0, 1024) != -1) {
                System.out.print(cbuf);
            }
            System.out.println();
            logger.debug("Elemento <{}> assinado e inserido em <{}>.", elementToSign.getTagName(), parentElement.getTagName());
        } catch (Exception e) {
            throw new IllegalArgumentException("Impossível construir assinatura, ", e);
        }
    }

在我的调试步骤中,我看到signatureFactory.newXMLSignature(signedInfo,keyInfo)返回相同的实例,有人可以帮助newXMLSingature不会实例化一个新对象吗?

由于

0 个答案:

没有答案