Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compare 2 x509 certificate in java

I have been provided a byte array and an X509 certificate. I can generate X509 certificate from the byte array using below code.

CertificateFactory certificatefactory = CertificateFactory.getInstance("X.509");
InputStream in = new ByteArrayInputStream(bytes);
X509Certificate cert = (X509Certificate)certificatefactory.generateCertificate(in);

Please guide me how to verify that the generated X509 with the one which was provided to me.

like image 516
user3212372 Avatar asked Apr 13 '15 18:04

user3212372


1 Answers

Simply use certificate.equals(otherCertificate) : the equals() method will compare them correctly, with a specific implementation for each certificate subclass.

See the javadoc.

like image 68
JM Lord Avatar answered Oct 18 '22 05:10

JM Lord