Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix the error "Subject class type invalid."

Tags:

java

pki

ca

I use java to code a CA module to create and sign the certificate. When I run my code, the error "Subject class type invalid." appeared, but in the destination folder I can get the two files: rooca.crt and rootca.pfx. The certificate contains the information I set. Maybe the code is result is right, but I still want to fix the error.

The details of the exception:

java.security.cert.CertificateException: Subject class type invalid.
at sun.security.x509.X509CertInfo.setSubject(Unknown Source)
at sun.security.x509.X509CertInfo.set(Unknown Source)
at com.koal.Test.createIssueCert(Test.java:124)
at com.koal.Test.main(Test.java:353)

Part of my code: enter image description here enter code here

like image 695
gann yee Avatar asked Jul 26 '16 03:07

gann yee


2 Answers

I faced a similar problem. This code is working well with Java 1.6 and fail with this exception while running on Java 1.8.

I can fix this issue by implementing the following solution.

In fact, in Java 1.8, it seems that you do not have to encapsulate anymore the X500Name into CertificateSubjectName or CertificateIssuerName. You can store the X500Name object directly in the X509CertInfo instance.

like image 129
Sébastien Vanmechelen Avatar answered Nov 19 '22 18:11

Sébastien Vanmechelen


Change this "info.set(X509CertInfo.SUBJECT, new CertificateSubjectName(subject));" To info.set(X509CertInfo.SUBJECT, subject); it work for me

like image 22
user9303726 Avatar answered Nov 19 '22 20:11

user9303726