Pdf 为什么我有1个杂项更改-如果我添加文档安全存储

Pdf 为什么我有1个杂项更改-如果我添加文档安全存储,pdf,adobe,digital-signature,bouncycastle,pdfbox,Pdf,Adobe,Digital Signature,Bouncycastle,Pdfbox,我已经在文件上签字了。我想将DSS添加到我的文档中 Security.addProvider(new BouncyCastleProvider()); File signedDocument = new File("/signed.pdf"); File out = new File("/signed_plus_dss"); byte[] buffer = new byte[8 * 1024]; FileInpu

我已经在文件上签字了。我想将DSS添加到我的文档中

        Security.addProvider(new BouncyCastleProvider());

        File signedDocument = new File("/signed.pdf");
        File out = new File("/signed_plus_dss");

        byte[] buffer = new byte[8 * 1024];
        FileInputStream fis = new FileInputStream(signedDocument);
        FileOutputStream fos = new FileOutputStream(out);

        int c;
        while ((c = fis.read(buffer)) != -1) {
            fos.write(buffer, 0, c);
        }
        fis.close();
        fis = new FileInputStream(out);

        // load document
        PDDocument doc = PDDocument.load(signedDocument);
        PDDocumentCatalog catalog = doc.getDocumentCatalog();
        COSDictionary catalogDictionary = catalog.getCOSDictionary();
        COSDictionary dssDictionary = new COSDictionary();

        /* ... I can add OCSP responses, and CRLS, and Certs here    
            in order to create document LTV, but now I don't need that. 
            I have another problem, not this... */


        /* if that's false, nothing happens */ 
        catalogDictionary.setNeedToBeUpdate(true);
        catalogDictionary.setItem(COSName.getPDFName("DSS"), dssDictionary);  

        /* ... if we add here Document level time stamp, everything is fine.
        signature will not be invalid with TSA. but it's invalid without TSA ... */  
        doc.saveIncremental(fis, fos);
就这样。一切都很好。当我看到PDF结构时,有一个文档安全存储。但是,当我使用adobe reader打开PDF时,我的签名无效,因为-“文档自签名后已被更改或损坏。”“1杂项更改”

但是,这里发生了一些有趣的事情-如果我添加Pades LTV(DSS+TSA),一切都正常:

例如,如果我们添加以下代码:

        URL tsaURL = new URL(TSAUrl);
        PDSignature signature = new PDSignature();
        signature.setFilter(PDSignature.FILTER_ADOBE_PPKLITE); 
        signature.setSubFilter(COSName.getPDFName("ETSI.RFC3161"));
        signature.setSignDate(Calendar.getInstance());
        TimestampeInt signatureInt = new TimestampeInt(tsaURL, null, null);
        doc.addSignature(signature, signatureInterface);
        doc.saveIncremental(fis, fos);
结果,文档级别的时间桩工作良好。但是我需要只添加DSS,而不添加TSA。我怎样才能解决这个问题,你怎么看


示例文档:

虽然在原始签名文档和添加了DSS和时间戳的文档中,AcroForm字典是目录中的直接对象,但在仅添加了DSS的文档中是间接对象:

SIGN.pdf:

5 0 obj
<<
/Type /Catalog
/Pages 3 0 R
/AcroForm <<
/Fields [7 0 R]
/SigFlags 3
>>
>> 
endobj
50对象
>> 
endobj
SIGN+DSS.pdf:

5 0 obj
<<
/Type /Catalog
/Pages 3 0 R
/AcroForm 12 0 R
/DSS 13 0 R
>>
endobj
12 0 obj
<<
/Fields [7 0 R]
/SigFlags 3
>> 
endobj
50对象
>
endobj
12 0 obj
> 
endobj
SIGN+DSS+TSA.pdf:

5 0 obj
<<
/Type /Catalog
/Pages 3 0 R
/AcroForm <<
/Fields [7 0 R 12 0 R]
/SigFlags 3
>>
/DSS 13 0 R
>> 
endobj
50对象
/DSS130R
>> 
endobj
虽然这对于手边的文档是等效的,但Adobe Reader可能对此感到困惑

我修补了你的SIGN+DSS.pdf,将AcroForm字典作为目录中的直接对象,Adobe Reader很高兴


mkl。你总是很棒!p、 使用编辑器,您是否使用十六进制值一起查看两个文档(以查看差异)?我只有Araxis Merge。@LadyBird我使用Total Commander的比较函数进行了比较,该函数可以作为文本或二进制文件进行比较。这两种比较模式在PDF分析中都很有趣。但肯定还有很多其他的比较工具允许同样的情况。