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);
    }

 

posted @ 2015-03-06 11:17  哎呦喂,我的小祖宗╰つ  阅读(2757)  评论(0编辑  收藏  举报