有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java XMLSignature newXMLSignature返回相同的实例

我想为巴西人的财政票据开发一个签名生成器。当我的系统在同一范围内对两个不同的xmls文件进行签名时,第二个签名验证失败。 我想问题出在我制作签名的方法上

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)返回同一个实例,有人可以帮助处理newXMLSignature不实例化新对象吗

谢谢


共 (0) 个答案