我有一个基于XFA的PDF,需要签名一些字段。但是,这些字段嵌入在XFA表单中,因此我无法使用以下代码对其进行签名
public void sign(String keystore, char[] password, String src, String name, String dest)
throws GeneralSecurityException, IOException, DocumentException {
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(new FileInputStream(keystore), password);
String alias = (String)ks.aliases().nextElement();
PrivateKey pk = (PrivateKey) ks.getKey(alias, password);
Certificate[] chain = ks.getCertificateChain(alias);
// 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.setVisibleSignature(name);
// Creating the signature
PrivateKeySignature pks = new PrivateKeySignature(pk, DigestAlgorithms.SHA256, "BC");
ExternalDigest digest = new BouncyCastleDigest();
MakeSignature.signDetached(appearance, digest, pks, chain, null, null, null, 0, MakeSignature.CryptoStandard.CMS);
}
例如,我有一个名为" root [0] .mainpage [0] .root [2] .DefaultPage [0] .Page1 [0] .SignArea [0] .GSA [0]的字段。 GSF-shinfo_sh-tmp03_sh_sf [0]&#34 ;.当我试着把它放到参数#34; name"时,我收到了错误信息
"线程中的异常" main" java.lang.IllegalArgumentException:字段root [0] .mainpage [0] .root [2] .DefaultPage [0] .Page1 [0] .SignArea [0] .GSA [0] .GSF-shinfo_sh-tmp03_sh_sf [0 ]不存在。"
我已经解决了这个问题一个星期,但我还没有找到解决方案。关于这个问题有什么想法吗?谢谢!
PS:这是文件的download url。