从证书获取公钥 [英] Obtaining public key from certificate

查看:1010
本文介绍了从证书获取公钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用以下方法获取证书的公钥:

I'm trying to obtain the public key of a Certificate using the method:

FileInputStream fin = new FileInputStream("PathToCertificate");
CertificateFactory f = CertificateFactory.getInstance("X.509");
X509Certificate certificate = (X509Certificate)f.generateCertificate(fin);
PublicKey pk = certificate.getPublicKey();

但我收到以下错误:

Exception in thread "main" java.lang.ClassCastException: sun.security.x509.X509CertImpl cannot be cast to codec.x509.X509Certificate
        at sergas_testcertificates.Main.main(Main.java:54)

有人知道这个错误是什么吗?

Does anyone know what this error is about?

提前感谢

推荐答案

X509Certificate 。

您可能正在寻找 java.security.cert.X509Certificate code> codec.x509.X509Certificate

You are likely looking for java.security.cert.X509Certificate not codec.x509.X509Certificate.

这篇关于从证书获取公钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆