我有一个问题,我不知道如何解决。我的应用程序收到一个(据说)签名的 XML,我必须验证它是否正确。这是 XML 中接收内容的签名部分
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<Reference URI="35121103220612000188550010000000131000009300">
<Transforms>
<Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
<Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<DigestValue>uLZ/66r6OoNLpj5v4cIsrv5zmyc=</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>encoded</SignatureValue>
<KeyInfo>
<X509Data>
<X509Certificate>encoded</X509Certificate>
</X509Data>
</KeyInfo>
</Signature>
我在互联网上找到的所有要验证的东西都需要公钥。但我没有。我只有 DigestValue。您知道是否可以仅使用 DiggestValue 进行验证?
这是我到目前为止所拥有的。问题是从哪里获取 X509KeySelector 的密钥
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder builder = dbf.newDocumentBuilder();
Document doc = builder.parse("/home/test.xml");
Node nl = doc.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature").item(0);
DOMValidateContext valContext = new DOMValidateContext(new X509KeySelector(publicKey), nl);
XMLSignatureFactory factory = XMLSignatureFactory.getInstance("DOM");
XMLSignature signature = factory.unmarshalXMLSignature(valContext);
System.out.println(signature.validate(valContext));
提前致谢。