我正在准备pdf文档的MessageDigest(SHA256)并将其发送到签名Web服务。该服务向我返回了XMLSignature。为了给我的pdf签名,我尝试将这个XML签名附加到它。如何在Java中执行此操作?
当我使用google时,我能够找到许多与用于签名XML内容的XMLSignature相关的引用,但是我找不到如何将XMLSignature用来签名PDF文档?
我知道如何使用私钥将证书附加到pdf,但是无法弄清楚必须使用XML签名的原因。
我能够像下面这样到达XML签名。
InputStream certificateIS = new ByteArrayInputStream(decoder.decode({base64_encoded_certificate}));
CertificateFactory f = CertificateFactory.getInstance("X.509");
X509Certificate certificate = (X509Certificate)f.generateCertificate(certificateIS);
PublicKey pk = certificate.getPublicKey();
//getSignatureElement returns the <Signature> element of the XML returned from the web service
Element signatureElement = getSignatureElement();
if(null!=signatureElement) {
DOMValidateContext context = new DOMValidateContext(pk, signatureElement);
XMLSignatureFactory factory = XMLSignatureFactory.getInstance("DOM");
XMLSignature signature = factory.unmarshalXMLSignature(context);
}
此后我该如何进行?