title: problem reading a publickey file and use the key to encrypt another file
body: <p>I've been strugling with reading a publickey file which I want to get the key sting in the file and use it to encrypt another file. I'm using RSA PKCS1 v1.5 in encrypting and signing the file with SH1 hashing algorythim but thats not the problem, the problem is that I've been supplied with the publickey file to use when encrypting and I cant seem to win with reading the file and generating a publicKey object.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>void setPublicKey(String file) 
  { 
       try 
       { 
         FileInputStream keyfis = new FileInputStream(file); 
         byte[] encKey = new byte[keyfis.available()]; keyfis.read(encKey);
         keyfis.close();
         X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(encKey);
         KeyFactory keyFactory = KeyFactory.getInstance("RSA");
  // I get an exception on the below line
         publicKey = keyFactory.generatePublic(pubKeySpec);
       } catch (Exception e)
         {
           e.printStackTrace();
         }
  }
  </code></pre>
  
  <p>Can someone please help!!</p>