Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javax.security.cert.X509Certificate vs java.security.cert.X509Certificate?

Tags:

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?

like image 256
Narobik Olga Avatar asked Dec 11 '10 01:12

Narobik Olga


People also ask

What is X509Certificate in Java?

public abstract class X509Certificate extends Certificate. Abstract class for X. 509 v1 certificates. This provides a standard way to access all the version 1 attributes of an X. 509 certificate.

What is Java security cert?

The Java Certificate class ( java. security. cert. Certificate ) represents a cryptographic identity certificate. A Java Certificate class instance contains name plus other details of the entity it identifies, plus possibly a digital signature from a Certificate Authority (CA).

What is the purpose of the javax certificate class?

This class is an abstraction for certificates that have different formats but important common uses. For example, different types of certificates, such as X. 509 and PGP, share general certificate functionality (like encoding and verifying) and some types of information (like a public key).


2 Answers

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

like image 177
President James K. Polk Avatar answered Sep 22 '22 14:09

President James K. Polk


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; 
like image 36
Venu Avatar answered Sep 20 '22 14:09

Venu