我刚刚在我的 pdf 中添加了时间戳。签名有效。时间戳记号也是正确的(我已经检查过了)。但 adobe reader 告诉我“签名包含嵌入式时间戳,但无法验证”。
AttributeTable unsigned = signerInformation.getUnsignedAttributes();
Hashtable<ASN1ObjectIdentifier, Attribute> unsignedAttrHash = null;
if (unsigned == null) {
unsignedAttrHash = new Hashtable<ASN1ObjectIdentifier, Attribute>();
} else {
unsignedAttrHash = signerInformation.getUnsignedAttributes().toHashtable();
}
unsignedAttrHash.put(PKCSObjectIdentifiers.id_aa_signatureTimeStampToken, signatureTimeStamp);
SignerInformation newSignertInformation = SignerInformation.replaceUnsignedAttributes(si, new AttributeTable(unsignedAttrHash));
我 在 stackowerflow 找到了这段代码。有用。这真的是正确的代码。最后我有新的 SignerInformationStore 和新的 CMS Signed Data 像这样
CMSSignedData.replaceSigners(oldCMSSignedData, newSignerStore);
但也许我的 PDF 中缺少某些内容?证书之类的?