我使用 PDFBOX 创建了一个 PDF PAdES 签名,我正在使用 ETSI 在线验证器1(它需要注册),现在我在报告中只收到两个错误,但我有点迷失它们是什么或如何修复它们。
这是etsi在线验证器报告:
这是我用来签名的代码:
@Override
public byte[] sign(InputStream content) throws IOException {
try {
CMSSignedDataGenerator signGenerator = new CMSSignedDataGenerator();
X509Certificate userCert = (X509Certificate) this.certificateChain[0];
ContentSigner mySigner = new CustomSigner(this.signerKeyHandle);
// TODO check to use cavium as digest provider
MessageDigest md = MessageDigest.getInstance("SHA-256", "Cavium");
md.update(userCert.getEncoded());
byte[] userCertHash = md.digest();
X509CertificateHolder issuerCert = new X509CertificateHolder(this.certificateChain[1].getEncoded());
// IssuerSerial is = new IssuerSerial(issuerCert.get,
// issuerCert.getSerialNumber());
ESSCertIDv2 certid = new ESSCertIDv2(new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha256),
userCertHash);
ESSCertIDv2[] essCert1Arr = { certid };
SigningCertificateV2 sigcert = new SigningCertificateV2(certid);
final DERSet attrValues = new DERSet(sigcert);
Attribute attr = new Attribute(PKCSObjectIdentifiers.id_aa_signingCertificateV2, attrValues);
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(attr);
AttributeTable atttributeTable = new AttributeTable(v);
//Create a standard attribute table from the passed in parameters - certhash
CMSAttributeTableGenerator attrGen = new DefaultSignedAttributeTableGenerator(atttributeTable){
protected Hashtable createStandardAttributeTable(Map parameters)
{
Hashtable result = super.createStandardAttributeTable(parameters);
result.remove(CMSAttributes.signingTime);
return result;
}
};
JcaSignerInfoGeneratorBuilder signerBuilder = new JcaSignerInfoGeneratorBuilder( new JcaDigestCalculatorProviderBuilder().build());
signerBuilder.setSignedAttributeGenerator(attrGen);
SignerInfoGenerator signerInfoGenerator = signerBuilder.build(mySigner, userCert);
signGenerator.addSignerInfoGenerator(signerInfoGenerator);
signGenerator.addCertificates(new JcaCertStore(Arrays.asList(certificateChain)));
CMSProcessableInputStream msg = new CMSProcessableInputStream(content);
CMSSignedData signedData = signGenerator.generate(msg, false);
return signedData.getEncoded();
} catch (GeneralSecurityException | CMSException | OperatorCreationException e) {
System.err.println(e.getMessage());
throw new RuntimeException("unable to sign pdf!");
}
}
我不太确定这些问题可能出在哪里或为什么会产生,一开始我有 5 个,现在我只有这两个,所以任何输入都将不胜感激