PDF 签名无效但使用 PDFBox2 验证签名有效(真)

问题描述 投票:0回答:0

PDF 签名无效但使用 PDFBox2 验证签名有效(真)

PDF样本下载:

https://drive.google.com/file/d/18CY_6qe_xog9Zil0qNhF_o6h4Cs6VW6Z/view?usp=sharing

因此,当在 A.Reader(连续发布)中打开 PDF 时,它表示证书无效,因为对该文档进行了更改,导致签名无效。

但我看不出有什么问题。我们自己的应用程序只添加了一个签名(证书),它为数以千计的其他 PDF 添加了正确的签名。没有执行其他更改。使用我们自己的代码验证哈希或使用带有以下代码的 PDFBox2 表明签名有效(真实)。

使用此代码验证:

    byte[] pdfByte;
    PDDocument pdfDoc = null;
    SignerInformationVerifier verifier = null;
    try
    {
        pdfByte = FileUtils.readFileToByteArray(new File(FOLDEROUT, "Example-link-fails.pdf"));  
        pdfDoc = PDDocument.load(new File(FOLDEROUT, "Example-link-fails.pdf"));  
       // pdfDoc = Loader.loadPDF(new ByteArrayInputStream(pdfByte));
        PDSignature signature = pdfDoc.getSignatureDictionaries().get(0);

        byte[] signatureAsBytes = signature.getContents();
        byte[] signedContentAsBytes = signature.getSignedContent(pdfByte);
        CMSSignedData cms = new CMSSignedData(new CMSProcessableByteArray(signedContentAsBytes), signatureAsBytes);
        SignerInformation signerInfo = (SignerInformation) cms.getSignerInfos().getSigners().iterator().next();
        X509CertificateHolder cert = (X509CertificateHolder) cms.getCertificates().getMatches(signerInfo.getSID())
                .iterator().next();
        verifier = new JcaSimpleSignerInfoVerifierBuilder().setProvider(new BouncyCastleProvider()).build(cert);

        // result if false
        boolean verifyRt = signerInfo.verify(verifier);
        System.out.println("Verify result: " + verifyRt);
    }
    finally
    {
        if (pdfDoc != null)
        {
            pdfDoc.close();
        }
    }

为什么 A.Reader 会抱怨?

备注:其他带有链接的PDF被A.Reader接受了,所以现在一无所知。

非常感谢任何帮助((慢慢地)发疯):-(

pdf signature verify
© www.soinside.com 2019 - 2024. All rights reserved.