我有一个用Base64编码的证书- BEGIN certificate - MIIGezCCBWOgAwIBA ....,如何从它获取出现在证书路径中的根证书和中间证书!
发布于 2012-02-18 04:52:00
我以前也遇到过同样的问题。您可以看到,证书有一个Issuer字段,其中包含颁发者的主题。
您可以比较这一点,或者/您可以测试签名。只有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:
我使用的是受this启发的东西。
祝好运
https://stackoverflow.com/questions/3772961
复制相似问题