0

How could I check the validity of a PFX certificate programmatically using java?

I found various ways to do this (like using openssl), but none using Java.

Greelings
  • 4,964
  • 7
  • 34
  • 70

1 Answers1

0

You can acheive this using boucycastle libraries. Check below github project for the same which read the p12 file and get the certificate details.

https://github.com/rosmahajan/java-read-p12

It is simple java class loading the p12/pfx file and read the certificate details. Once you get the x509Certificate object try below command to check the validity of certificate

x509.checkValidity();

Sometime renaming pfx file to p12 works as both are PKCS#12 file but if renaming doesn't work , try below to convert pfx to p12 using keytool

keytool -importkeystore -destkeystore new.p12 -deststoretype pkcs12 -srckeystore original.pfx

For more information: convert pfx format to p12

Rmahajan
  • 1,311
  • 1
  • 14
  • 23