Android : Check the validity of a PFX certificate

1.2k Views Asked by At

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.

1

There are 1 best solutions below

0
Rmahajan On

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