如何使用Java中的BouncyCastle提供程序驗證分離簽名(CMS/pkcs#7簽名)?使用BC驗證分離簽名
目前,我的代碼如下拋出與消息message-digest attribute value does not match calculated value
Security.addProvider(new BouncyCastleProvider());
File f = new File(filename);
byte[] buffer = new byte[(int)f.length()];
DataInputStream in = new DataInputStream(new FileInputStream(f));
in.readFully(buffer);
in.close();
CMSSignedData signature = new CMSSignedData(buffer);
SignerInformation signer = (SignerInformation) signature.getSignerInfos().getSigners().iterator().next();
CertStore cs = signature.getCertificatesAndCRLs("Collection", "BC");
Iterator iter = cs.getCertificates(signer.getSID()).iterator();
X509Certificate certificate = (X509Certificate) iter.next();
CMSProcessable sc = signature.getSignedContent();
signer.verify(certificate, "BC");
您是否測試過在此處找到的代碼:http: //bouncy-castle.1462172.n4.nabble.com/How-to-verify-detached-PKCS7-signature-with-Stream-content-data-td1464668.html?目前,您並沒有特別的地方將您分離的數據考慮在內。 –
我解決了這個問題,你可以找到答案[這裏] [1] [1]:http://stackoverflow.com/questions/8590426/s-mime-verification-with-x509-certificate/20649242 #20649242 – Swapnil