title: KeyStore.load method throws java.io.IOException : extra data given to DerValue constructor
body: <p>I was looking for a solution,but nothing I have already found solved my problem.
  I am trying to simply add a new Key to an existing KeyStore file,but it seemes like I can't add more than one Key, cause this exceptions occurs on the second call of function for adding a new Key in main method and on the bolded KeyStore.load method.
  Here is my method: </p>
  
  <pre><code>    String keyPass="pass"; 
  
      KeyStore keyStore = KeyStore.getInstance("jks");
      char[] storePass = this.keyStorePass.toCharArray();
      FileInputStream is = new FileInputStream(this.keyStoreName);
      **keyStore.load(is,storePass);** 
      is.close();
  
      Certificate[] certChain = new Certificate[1];  
      certChain[0] = this.certificate;  
      keyStore.setKeyEntry(key, this.pair.getPrivate(), keyPass.toCharArray(), certChain); 
  
      FileOutputStream fos = new FileOutputStream(this.keyStoreName);
      keyStore.store(fos, storePass);
      fos.close();
  </code></pre>
  
  <p>Here is the exception: </p>
  
  <pre><code>   `java.security.cert.CertificateParsingException: java.io.IOException:
      extra data given to DerValue constructor
     at sun.security.x509.X509CertInfo.&lt;init&gt;(Unknown Source)
     at sun.security.x509.X509CertImpl.parse(Unknown Source)
     at sun.security.x509.X509CertImpl.&lt;init&gt;(Unknown Source)
     at sun.security.provider.X509Factory.engineGenerateCertificate
     at java.security.cert.CertificateFactory.generateCertificate
     at sun.security.provider.JavaKeyStore.engineLoad
     at sun.security.provider.JavaKeyStore$JKS.engineLoad(Unknown Source)
     at java.security.KeyStore.load(Unknown Source)
     at zp2016.StorageClass.addToMyKeyStore(StorageClass.java:76)
     at zp2016.MainProgram.main(MainProgram.java:76)
  </code></pre>
  
  <p>`</p>
  
  <p>Certificate chain has 1 element, cause the app is about self-signed X509 certificate.Thanks.</p>