小编mer*_*iem的帖子

用BC验证分离的签名

如何使用Java中的BouncyCastle提供程序验证分离的签名(CMS/pkcs#7签名)?

目前,我的代码会在邮件中引发异常 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");
Run Code Online (Sandbox Code Playgroud)

java bouncycastle digital-signature

6
推荐指数
2
解决办法
1万
查看次数

标签 统计

bouncycastle ×1

digital-signature ×1

java ×1