Android Question Access contents of a *.pfx file

KMatle

Expert
Licensed User
I'm able to extract the contents via OpenSSL (e.g. the private key) "by hand". Based on the example here Get contents of a certificate I'm able to get contents of a certificate but not a *,pfx file. So how do I get the contents of a *.pfx file? Example: https://stackoverflow.com/questions/15130548/how-can-i-read-the-content-of-a-pfx-file-in-java

B4X:
 public void checkExpire() {

        try {
            KeyManagerFactory kmf = javax.net.ssl.KeyManagerFactory.getInstance("SunX509");
            KeyStore keystore = KeyStore.getInstance("PKCS12");
            char[] password= "yourfilepassword".toCharArray();

            keystore.load(new FileInputStream("filepath\filename.pfx"),password);
            //keystore.load(new FileInputStream(certificate), password);
            kmf.init(keystore, psswd);
            Enumeration<String> aliases = keystore.aliases();
            while(aliases.hasMoreElements()){
                String alias = aliases.nextElement();
                if(keystore.getCertificate(alias).getType().equals("X.509")){
                Date expDate = ((X509Certificate) keystore.getCertificate(alias)).getNotAfter();
                Date fromDate= ((X509Certificate) keystore.getCertificate(alias)).getNotBefore();
        System.out.println("Expiray Date:-"+expDate );
        System.out.println("From Date:-"+fromDate);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

Note: I've installed the *.pfx file on my phone after downloading it. Now I want to access the contents to sign messages with the private key (I know how to sign but I'm not able to access the contents).
 
Top