public void importPKCS8(BurpCertificate certificate,String filename){
  setStatus("Importing private key...");
  FileInputStream fis;
  File file=new File(filename);
  PrivateKey privateKey;
  try {
    fis=new FileInputStream(file);
    DataInputStream dis=new DataInputStream(fis);
    byte[] keyBytes=new byte[(int)file.length()];
    dis.readFully(keyBytes);
    dis.close();
    PKCS8EncodedKeySpec keySpec=new PKCS8EncodedKeySpec(keyBytes);
    KeyFactory keyFactory=KeyFactory.getInstance("RSA");
    privateKey=keyFactory.generatePrivate(keySpec);
    certificate.setPrivateKey(privateKey);
    setCertificateTree();
    setStatus("Private Key imported.");
  }
 catch (  IOException|NoSuchAlgorithmException|InvalidKeySpecException e) {
    setStatus("Error importing private Key. (" + e.getMessage() + ")");
    e.printStackTrace();
  }
catch (  Exception e) {
    setStatus("Error (" + e.getMessage() + ")");
  }
}

public void importPKCS8 ( BurpCertificate certificate , String filename ) { setStatus ( "Importing private key..." ) ; FileInputStream fis ; File file = new File ( filename ) ; PrivateKey privateKey ; try { fis = new FileInputStream ( file ) ; DataInputStream dis = new DataInputStream ( fis ) ; byte [ ] keyBytes = new byte [ ( int ) file . length ( ) ] ; dis . readFully ( keyBytes ) ; dis . close ( ) ; PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec ( keyBytes ) ; KeyFactory keyFactory = KeyFactory . getInstance ( "RSA" ) ; privateKey = keyFactory . generatePrivate ( keySpec ) ; certificate . setPrivateKey ( privateKey ) ; setCertificateTree ( ) ; setStatus ( "Private Key imported." ) ; } catch ( IOException | NoSuchAlgorithmException | InvalidKeySpecException e ) { setStatus ( "Error importing private Key. (" + e . getMessage ( ) + ")" ) ; e . printStackTrace ( ) ; } catch ( Exception e ) { setStatus ( "Error (" + e . getMessage ( ) + ")" ) ; } }
import a private key in pkcs8 format in der format .
