Java - 获取证书链
我有一个以 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我以前也遇到过同样的问题。您会看到,证书有一个颁发者字段,其中包含颁发者的主题。
您可以进行比较,或者/并且您可以测试签名。只有 CA 才能验证证书的签名。
像这样的事情:
我没有测试代码,但你明白了。
编辑:
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:
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