Why a invalid keystore format exception?

  • Follow


Hi everyone.

I'm working a java code to upload files to a server. Before trying to open
an SSL connection to the destination host, I want to add his certificate
to the KeyStore with my trusted certificates. I found an usefull example
here http://blogs.sun.com/andreas/entry/no_more_unable_to_find
so I adapted a little the code  

KeyStore ks = KeyStore.getInstance("JKS");
File file = new File("jssecacerts");
InputStream in = new FileInputStream(file);
  if (in.read()!=-1) 
      ks.load(in, "changeit".toCharArray()); [*]    <== exception
  else
      ks.load(null, "changeit".toCharArray());
in.close();

but when I'm executing my code once a first certificate has been added to
the KeyStore I go still this exception on the point [*]

java.io.IOException: Invalid keystore format
at sun.security.provider.JavaKeyStore.engineLoad(Unknown Source)
at sun.security.provider.JavaKeyStore$JKS.engineLoad(Unknown Source)
at java.security.KeyStore.load(Unknown Source)

What i'm doing wron?
TIA for your help. 


-- 

questo articolo e` stato inviato via web dal servizio gratuito 
http://www.newsland.it/news segnala gli abusi ad abuse@newsland.it


0
Reply gianpaolo77 4/23/2009 7:09:12 PM

> InputStream in = new FileInputStream(file);
>   if (in.read()!=-1) 
>       ks.load(in, "changeit".toCharArray()); [*]    <== exception
>   else
>       ks.load(null, "changeit".toCharArray());
> 
> What i'm doing wron?

Why do you read the first byte of the stream manually and expect
KeyStore to handle a now incomplete byte stream?

Ronny

0
Reply Ronny 4/23/2009 8:17:25 PM


1 Replies
828 Views

(page loaded in 0.025 seconds)

Similiar Articles:













7/25/2012 5:46:18 PM


Reply: