简体   繁体   English

如何在Java中打开X509证书?

[英]How to open X509 certificate in java?

I was trying to open a crt certificate in java and hence thereby get some parameters from the crt. 我试图在Java中打开crt证书,从而从crt获取一些参数。 I used the following code: 我使用以下代码:

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

When I run the code, the compiler throws certificate exception at line 2. Is it because of the certificate that I'm using? 当我运行代码时,编译器将在第2行引发证书异常。是否是因为我使用的证书? Or what changes in code should I make? 还是应该对代码进行哪些更改?

Or is there any alternative way to access a certificate and extract the details? 还是有其他方法可以访问证书并提取详细信息?

When I run the code, the compiler throws certificate exception at line 2. 当我运行代码时,编译器在第2行抛出证书异常。

No it doesn't. 不,不是。 The compiler doesn't throw exceptions. 编译器不会抛出异常。 It prints compilation errors. 它显示编译错误。

Is it because of the certificate that I'm using? 是因为我使用的证书吗?

No. 没有。

Or what changes in code should I make? 还是应该对代码进行哪些更改?

Catch the exception named in the error message, or declare it to be thrown by the method. 捕获错误消息中命名的异常,或声明该异常由方法抛出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM