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不会实例化一个新对象吗?
由于