javax.security.cert.X509Certificate vs java.securi

2020-08-09 06:04发布

Did you spot the difference in the title? (for me, it took some time)

So I used bouncy castle with connection to java.security.cert.X509Certificate in order to create certificates. Now I'm looking for a way to create a java.security.cert.X509Certificate from raw bytes. I haven't any method to do this in java.security.cert.X509Certificate but there is one(the getInstance static method) in javax.security.cert.X509Certificate.

The problem is I cannot cast a javax.security.cert.X509Certificate to java.security.cert.X509Certificate.

Any ideas on what to do, to transform raw bytes into a java.security.cert.X509Certificate?

Also, what's the differences between the one abstract class and the other class? Why does java has two of them with different functionality?

2条回答
家丑人穷心不美
2楼-- · 2020-08-09 06:26

The javax version is deprecated. Use CertificateFactory to generate a certificate from raw bytes. There is an example in the javadocs.

查看更多
孤傲高冷的网名
3楼-- · 2020-08-09 06:30

This happened for me because I am using j2se but imported javax classes. Certificate and X509Certficate classes exists both in J2SE and in J2EE.

Imports in J2SE - Not javax.security...

import java.security.KeyStore;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;

import java.security.cert.Certificate;

Not these.

import javax.security.cert.X509Certificate;
查看更多
登录 后发表回答