在Java中需要一些加密例程的帮助.
鉴于PKCS#7签名,我想验证它对可信商店包含的所有证书.我假设签名中包含的所有证书都以正确的顺序形成有效的证书路径(或链,无论如何),以便这样做
最后一个证书(#N)由CA签名.
这就是我到目前为止所做的事情:
// Exception handling skipped for readability
//byte[] signature = ...
pkcs7 = new PKCS7(signature); // `sun.security.pkcs.PKCS7;`
// *** Checking some PKCS#7 parameters here
X509Certificate prevCert = null; // Previous certificate we've found
X509Certificate[] certs = pkcs7.getCertificates(); // `java.security.cert.X509Certificate`
for (int i = 0; i < certs.length; i++) {
// *** Checking certificate validity period here
if (cert != null) {
// Verify previous certificate in chain against this one
prevCert.verify(certs[i].getPublicKey());
}
prevCert …
Run Code Online (Sandbox Code Playgroud)