2015-01-13 54 views
0

我试图在java中打开一个crt证书,因此从crt获取一些参数。我用下面的代码:如何在java中打开X509证书?

inStream = new FileInputStream("sbi.crt"); 
CertificateFactory cf = CertificateFactory.getInstance("X.509"); 
X509Certificate cert = (X509Certificate)cf.generateCertificate(inStream); 

当我运行的代码,编译器会引发在第2行证书的例外是不是因为我使用的证书?我应该做什么代码更改?

或者是否有任何其他方式来访问证书并提取细节?

+0

什么异常,其中 –

+0

这是抛出的异常:异常在线程“主要” java.lang.Error的:未解决的编译问题: \t未处理的异常类型CertificateException \t未处理的异常类型CertificateException \t在filehand.handle。 main(handle.java:30) – John

+0

这里第30行是第2行 – John

回答

0

When I run the code, the compiler throws certificate exception at line 2.

不,它不。编译器不会抛出异常。它打印编译错误。

Is it because of the certificate that I'm using?

Or what changes in code should I make?

捕捉在错误消息中指定的异常,或者声明它通过该方法被抛出。

+0

谢谢你..现在工作! – John