title: Not able to load P7B file into keystore file
body: <p>I received a new certificate in <code>crt</code> / <code>cert</code> format. When I open this file in a text editor they added the complete certificate chain to this file. Each certificate starts with:</p>
  
  <pre><code>-----BEGIN CERTIFICATE-----
  </code></pre>
  
  <p>And ends with:</p>
  
  <pre><code>-----END CERTIFICATE-----
  </code></pre>
  
  <p>There are no empty lines in between. Since I am not keen with <code>openssl</code>, I opened up the certificate into Windows and exported the certificate with the complete chain in <code>PKCS#7</code> format (test.p7b). When I open this file all looks fine in Windows and the root, intermediate and the certificate are all their in the chain.</p>
  
  <p>When I put the file <code>test.p7b</code> on the server and try to import this with <code>keytool</code> as follows:</p>
  
  <pre><code>keytool -import -trustcacerts -alias my.domain.com -keystore my.domain.keystore -keypass changeme -storepass changeme -file test.p7b
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>keytool error: java.lang.Exception: Input not an X.509 certificate
  </code></pre>
  
  <p>When I test the P7B file I also get errors:</p>
  
  <pre><code>bash-4.1$ openssl x509 -in test.p7b -text
  unable to load certificate
  140009984849736:error:0906D06C:PEM routines:PEM_read_bio:no start line:pem_lib.c:698:Expecting: TRUSTED CERTIFICATE
  </code></pre>
  
  <p>or:</p>
  
  <pre><code>bash-4.1$ openssl x509 -in test.p7b -inform DER -text
  unable to load certificate
  140396587853640:error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag:tasn_dec.c:1320:
  140396587853640:error:0D07803A:asn1 encoding routines:ASN1_ITEM_EX_D2I:nested asn1 error:tasn_dec.c:382:Type=X509_CINF
  140396587853640:error:0D08303A:asn1 encoding routines:ASN1_TEMPLATE_NOEXP_D2I:nested asn1 error:tasn_dec.c:752:Field=cert_info, Type=X509
  </code></pre>
  
  <p>Can someone help me out?</p>