java解析pfx


public static void main(String[] args) throws Exception {
        String path = "D://111.pfx";
        InputStream in = new FileInputStream(new File(path));
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        KeyStore keyStore = KeyStore.getInstance("PKCS12");
        keyStore.load(in, "111".toCharArray());
        keyStore.store(out, "111".toCharArray());
        String b64 = new String(Base64.encode(out.toByteArray()));
        System.out.println(b64);
        Enumeration<String> aliases = keyStore.aliases();
        String enumeration = null;
        while (true) {
            try {
                enumeration = aliases.nextElement();
                System.out.println(enumeration);
            } catch (NoSuchElementException e) {
                System.out.println("讀取完畢");
                break;
            }
        }
        java.security.cert.Certificate cert =  keyStore.getCertificate(enumeration);
        System.out.println(cert.toString());
        PrivateKey privateKey = (PrivateKey) keyStore.getKey(enumeration, "111".toCharArray());
        System.out.println(privateKey);
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM