根據幾篇文章,我發現現在可以使用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