Java - 获取证书链

发布于 2024-09-24 12:28:55 字数 97 浏览 3 评论 0原文

我有一个以 Base64 编码的证书 ----- BEGIN 证书 - - - MIIGezCCBWOgAwIBA ....,如何从中获取出现在证书路径中的根证书和中间证书!

I have a certificate encoded in Base64 ----- BEGIN
CERTIFICATE -----
MIIGezCCBWOgAwIBA ...., how to get the root and intermediate certificates that appear in the certification path from it!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

草莓味的萝莉 2024-10-01 12:28:55

我以前也遇到过同样的问题。您会看到,证书有一个颁发者字段,其中包含颁发者的主题。
您可以进行比较,或者/并且您可以测试签名。只有 CA 才能验证证书的签名。
像这样的事情:

//load all the ca certificates and get their public keys
caCertificate.getIssuerDN().equals(caCertificate[i].getSubjectDN());
// OR/AND

try {
   verifySignature(certificate,
        caCertificate[i].getPublicKey());
    //issuer found
}
catch (Exception e) {
    // not the issuer
}

我没有测试代码,但你明白了。

编辑:

java中有一些专门用于验证链的类。其中之一是CertPathBuilder 类。我还在研究如何使用它。我总是用错误的参数创建它,我想...

编辑2:

我正在使用一些灵感来自 这个

祝你好运

I had the same problem before. You see, the certificate have an Issuer field, which has the issuer's subject.
You can compare that, or/and you can test the signature. Only the CA can verify the certificate's signature.
Something like this:

//load all the ca certificates and get their public keys
caCertificate.getIssuerDN().equals(caCertificate[i].getSubjectDN());
// OR/AND

try {
   verifySignature(certificate,
        caCertificate[i].getPublicKey());
    //issuer found
}
catch (Exception e) {
    // not the issuer
}

I didn't test the code, but you got the idea.

EDIT:

There are some classes in java that are specially made for validating a chain. one of them is the CertPathBuilder class. I am still researching on how to use it. I always create it with the wrong parameters, i suppose...

EDIT 2:

I am using something that was inspired by this.

good luck

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文