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