Adobe - 签名带有时间戳,但无法验证时间戳

时间:2018-06-06 11:02:14

标签: java itext adobe digital-signature rfc3161

我正在使用我的pdf文件上的时间戳创建签名。经过多次尝试,我们成功并签署了PDF文件。 Adobe验证了此文件,但时间戳有一个错误。有关于的信息:

Signature is timestamped but the timestamp could not be verified

此签名是否正确创建?

有代码

public String signByPfxCert(String filePath) {

        String postfix = "-signed";
        try {
            PdfReader reader = new PdfReader(filePath);
            OutputStream os = new FileOutputStream(filePath + postfix);

            PdfStamper stamper = PdfStamper.createSignature(reader, os, '\0');
            PdfSignatureAppearance appearance = stamper.getSignatureAppearance();
            appearance.setReason("REASON");
            appearance.setLocation("LOCATION");

            Security.addProvider(new BouncyCastleProvider());

            FileInputStream fis = new FileInputStream(getClass().getClassLoader().
                    getResource("clientcert.pfx").getFile());
            String password = "pwd12345";


            KeyStore ks = KeyStore.getInstance("PKCS12");
            ks.load(fis, password.toCharArray());
            String alias = ks.aliases().nextElement();

            PrivateKey pk = (PrivateKey) ks.getKey(alias, password.toCharArray());
            X509Certificate cert = (X509Certificate) ks.getCertificate(alias);

            com.itextpdf.text.pdf.security.TSAClient tsc = new TSAClientBouncyCastle(tsaUrl);
            ExternalDigest digest = new BouncyCastleDigest();
            ExternalSignature signature = new PrivateKeySignature(pk, "SHA-1", "BC");

            MakeSignature.signDetached(appearance, digest, signature, new Certificate[]{cert}, null, null, tsc, 0,
                    MakeSignature.CryptoStandard.CMS);


            if (fis.available() != 0) {
                fis.close();
            }

            File originalFile = new File(filePath);

            File signedFile = new File(filePath + postfix);

            boolean deleteOriginal = originalFile.delete();
            File destination = new File(filePath);
            boolean rename = signedFile.renameTo(destination);

            if(deleteOriginal && rename){
                return destination.getName();
            }else {
                return "";
            }


        } catch (Exception e) {
            e.printStackTrace();
        }

        return "";
    }

0 个答案:

没有答案