Java XML签名验证
我有个问题,我想不出怎么解决。 我的应用程序收到一个假定已签名的XML,我必须验证它是否正确。 下面是XML中接收内容的签名部分Java XML签名验证,java,xml,x509,Java,Xml,X509,我有个问题,我想不出怎么解决。 我的应用程序收到一个假定已签名的XML,我必须验证它是否正确。 下面是XML中接收内容的签名部分 <Signature xmlns="http://www.w3.org/2000/09/xmldsig#"> <SignedInfo> <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315
<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>
提前感谢。您可以从嵌入式X509证书获得X509密钥 更新:
在google搜索xml签名X509证书时出现了,这似乎可以为您提供所需的所有答案。您可以从嵌入的X509证书中获得X509密钥 更新:
在google搜索xml签名X509证书时,出现了一个问题,它似乎可以为您提供所需的所有答案。您可能需要在DocumentBuilderFactory上调用setNamespaceAwaretrue,否则它将引发以下异常:
Document implementation must support DOM Level 2 and be namespace aware
您可能需要在DocumentBuilderFactory上调用setNamespaceAwaretrue,否则它将引发以下异常:
Document implementation must support DOM Level 2 and be namespace aware
证书本身包含公钥:
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
InputStream in = new ByteArrayInputStream(Base64.getDecoder().decode(certificateStringFromXml));
X509Certificate cert = (X509Certificate)certFactory.generateCertificate(in);
PublicKey pk = cert.getPublicKey();
证书本身包含公钥:
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
InputStream in = new ByteArrayInputStream(Base64.getDecoder().decode(certificateStringFromXml));
X509Certificate cert = (X509Certificate)certFactory.generateCertificate(in);
PublicKey pk = cert.getPublicKey();
关键信息部分有什么?它真的是编码的还是其他的?我猜它包含您需要的证书。是的。我把它编码了,因为它是一个大字符串。但是它是一个编码字符串,KeyInfo部分有什么?它真的是编码的还是其他的?我猜它包含您需要的证书。是的。我把它编码了,因为它是一个大字符串。但它是一个编码的string@Haroldo示例链接似乎不起作用。我指的是链接本身。从这里起作用:@Haroldo示例链接似乎不起作用。我指的是链接本身。从这里起作用: