根据几篇文章,我发现现在可以使用BouncyCastle来执行CAdES,但几乎没有关于该主题的任何文档。使用BouncyCastle使用JAVA标记CAdES
对于初学者,我想在没有任何可选签名属性的情况下使用基于文件的证书对文件执行CAdES-BES。
针对皮屑:
我有可能会有所帮助,你有你的SignerInformation的东西,你需要扩展它,首先你需要创建一个时间戳的属性,我假设你已经有了一个TimeStampResponse作为tspResp
TimeStampToken token = tsresp.getTimeStampToken();
Attribute timeStamp = new Attribute(PKCSObjectIdentifiers.id_aa_signatureTimeStampToken, new DERSet(ASN1Object.fromByteArray(token.getEncoded())));
然后,你需要扩展SignerInformation
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 newsi = SignerInformation.replaceUnsignedAttributes(si, new AttributeTable(
unsignedAttrHash));
我认为就是这样。
这里是我得到的登入证书属性
Attribute signingCertificateAttribute;
MessageDigest dig = MessageDigest.getInstance(DigestAlgorithm().getName(),
new BouncyCastleProvider());
byte[] certHash = dig.digest(SigningCertificate().getEncoded());
if (DigestAlgorithm() == DigestAlgorithm.SHA1) {
SigningCertificate sc = new SigningCertificate(new ESSCertID(certHash));
signingCertificateAttribute = new Attribute(PKCSObjectIdentifiers.id_aa_signingCertificate, new DERSet(sc));
} else {
ESSCertIDv2 essCert = new ESSCertIDv2(new AlgorithmIdentifier(DigestAlgorithm().getOid()), certHash);
SigningCertificateV2 scv2 = new SigningCertificateV2(new ESSCertIDv2[] { essCert });
signingCertificateAttribute = new Attribute(PKCSObjectIdentifiers.id_aa_signingCertificateV2, new DERSet(scv2));
}
希望它可以帮助
感谢您提供的信息,您是否实施了“签署证书”(或签署证书-v2)签名属性?我在包含它时遇到了麻烦,您是否有任何特定的代码? – dande
我在sha1的情况下使用签名证书,在其他地方使用签名证书-v2,我将添加一些代码 – Radius
嗨,只是一个简短的问题,我无法得到我的头。你发送给时间戳服务器的数据是什么。我目前正在发送CMSignedData.getEncoded(),它显示签名上有一个时间戳,但它显示为无效:( – dande