在使用itext对文档进行数字签名时,如何确保最终pdf中是否对其进行了验证

问题描述

我正在使用iText的方法来用数字证书签署PDF,同时打开最终的pdf,我如何确保其经过验证。我已经看到一些经过数字签名的文档未显示针对其数字签名的经过验证的图像,即在我的数字附加了我的代码之前。

public void sign(String src,String dest,Certificate[] chain,PrivateKey pk,String digestAlgorithm,String provider,CryptoStandard subfilter,String reason,String location)
        throws GeneralSecurityException,IOException,DocumentException {

    // Creating the reader and the stamper
    PdfReader reader = new PdfReader(src);
    FileOutputStream os = new FileOutputStream(dest);
    pdfstamper stamper = pdfstamper.createSignature(reader,os,'\0',null,true);

    // Creating the appearance
    PdfSignatureAppearance appearance = stamper.getSignatureAppearance();
    appearance.setReason(reason);
    appearance.setLocation(location);
    appearance.setCertificationLevel(PdfSignatureAppearance.CERTIFIED_NO_CHANGES_ALLOWED);

    Rectangle cropBox = reader.getCropBox(1);
    float width = 200;
    float height = 61;

    // Bottom left
    Rectangle rectangle = new Rectangle(cropBox.getLeft(),cropBox.getBottom(),cropBox.getLeft(width),cropBox.getBottom(height));
    
    appearance.setVisibleSignature(rectangle,1,"sig");

    // Creating the signature
    ExternalDigest digest = new BouncyCastleDigest();
    ExternalSignature signature = new PrivateKeySignature(pk,digestAlgorithm,provider);
    MakeSignature.signDetached(appearance,digest,signature,chain,subfilter);
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)