title: Trust Store vs Key Store - creating with keytool
body: <p>I understand that the keystore would usually hold private/public keys and the trust store only public keys (and represents the list of trusted parties you intend to communicate with). Well, that's my first assumption, so if that's not correct, I probably haven't started very well...</p>
  
  <p><strong>I was interested though in understanding how / when you distinguish the stores when using keytool.</strong></p>
  
  <p>So, far I've created a keystore using</p>
  
  <pre><code>keytool -import -alias bob -file bob.crt -keystore keystore.ks
  </code></pre>
  
  <p>which creates my keystore.ks file. I answer <code>yes</code> to the question do I trust bob but it is unclear to me if this has created a keystore file or a truststore file? I can set up my application to use the file as either.</p>
  
  <pre><code>-Djavax.net.ssl.keyStore=keystore.ks -Djavax.net.ssl.keyStorePassword=x
  -Djavax.net.ssl.trustStore=keystore.ks -Djavax.net.ssl.trustStorePassword=x
  </code></pre>
  
  <p>and with <code>System.setProperty( "javax.net.debug", "ssl")</code> set, I can see the certificate under trusted certifications (but not under the keystore section). The particular certificate I'm importing has only a public key and I intend to use it to send stuff over an SSL connection to Bob (but perhaps that's best left for another question!).</p>
  
  <p>Any pointers or clarifications would be much appreciated. Is the output of keytool the same whatever you import and its just convention that says one is a keystore and the other a trust store? What's the relationship when using SSL etc?</p>