你基本上需要做的是构建一个证书链,如果你没有得到它作为一个链。证书链基本上由第零个位置的最终实体证书(也是叶证书,链中最重要的证书)组成,其次是次要证书。 CA证书是最不重要的。
所以这是通常的X.509证书链的样子:
3. CA Certificate (self-signed)
|
|__ 2. Sub CA Certificate (signed by the above CA)
|
|__ 1. Sub-sub CA Certificate (if any) (signed by the above Sub CA)
|
|__ 0. End Entity Certificate (your certificate, signed by the above cert)
当你构建一个证书链,从自己的每个证书,你有,你有看到哪个证书是由谁来签署然后以上述方式构建链(树中的数字表示java证书数组中的索引)。
你可以通过查看SubjectDN和IssuerDN找到哪个证书是由谁签署的。 Subject专有名称是最终实体,Issuer专有名称是签署证书的实体的名称。
如果您需要验证证书是否由另一个证书签名的程序,你可以这样做:
userCert.verify(caCert.getPublicKey());
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
// Provided the certificate doesn't have certificate headers (---begin cert--- and ---end cert---)
Certificate cert = certificateFactory.generateCertificate(new FileInputStream(new File("CERTIFICATE_PATH")));
System.out.println(cert.getPublicKey());
:
您可以使用此代码段提取的证书的公钥