如何在Java中验证PEM格式的证书
我有 PEM 格式文件,如何验证 Java 中的签名,正如我所遵循的 http://download.oracle.com/javase/tutorial/security/apisign/versig.html 但发现Java不支持PEM
I have PEM format file, How can verify the signature in Java, as I followed http://download.oracle.com/javase/tutorial/security/apisign/versig.html but found that Java doesnt support PEM
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 BouncyCastle 的
PEMReader
读取 PEM 文件中的证书。如果内容是 X.509 证书,您应该获取X509Certificate
的实例,并根据需要从那里验证它。:代码应如下所示(未尝试):(
当然,与任何 I/O 操作一样,您可能需要使用 try/finally 关闭阅读器。)
编辑
checkValidity
和verify
不会返回任何内容:相反,如果失败,它们会抛出异常。You can read a certificate in a PEM file using BouncyCastle's
PEMReader
. If the content is an X.509 certificate, you should get an instance ofX509Certificate
and verify it as you want from there.EDIT: Here is what the code should look like (not tried):
(Of course, as with any I/O operations, you'll need to close the reader perhaps with try/finally.)
Note that
checkValidity
andverify
don't return anything: instead, they throw exceptions if when they fail.