天天看点

Android之获取证书文件(pfx格式)的公钥和私钥

1、把pfx证书文件放入sdcard

adb push    ***.pfx /sdcard/
           

2、解析获取公钥和私钥

//证书解析
String path = Environment.getExternalStorageDirectory().getPath() + "/sim_shield.pfx";

   public static Map<String, byte[]> parsePfx(String pfxPath, String pwd) {
    	Map<String, byte[]> keyMap = new HashMap<String, byte[]>();
    	 try {
             KeyStore ks = KeyStore.getInstance("PKCS12");
             FileInputStream fis = null;
             try {
            	 fis = new FileInputStream(pfxPath);
             } catch (Exception e) {
            	 Log.i("sss", "new FileInputStream fail");
             }
             char[] nPassword = pwd.toCharArray();
             ks.load(fis, nPassword);
             fis.close();

             Enum