By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,468 Members | 1,859 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,468 IT Pros & Developers. It's quick & easy.

How to read SSL certificates?

P: n/a
I have several web servers with SSL certificates installed.
My plan is to write a java program which will grab the certs
via ftp, then read (parse) the certificate information.
Ultimately what I want is the expiration date. I found an
example of printing a cert (listed below), but get unresolved
symbol errors when compiling. I thought I needed the Java
Cryptography Extension (JCE), so I downloaded and installed
that, but still get the error. What do I need to do in order
to parse a Verisign certificate, in either .cer or .crt format?

-Thanks
import java.security.cert.*;
import java.io.*;

public class PrintCert {
public static void main(String args[]) {
try {
FileInputStream fr = new FileInputStream("sdo.cer");
X509Certificate c = X509Certificate.getInstance(fr);
System.out.println("Read in the following certificate:");
System.out.println("\tCertificate for: " + c.getSubjectDN());
System.out.println("\tCertificate issued by: " + c.getIssuerDN());
System.out.println("\tThe certificate is valid from " +
c.getNotBefore() + " to " + c.getNotAfter());
System.out.println("\tCertificate SN# " + c.getSerialNumber());
System.out.println("\tGenerated with " + c.getSigAlgName());
} catch (Exception e) {
e.printStackTrace();
}
}
}
Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.