title: Obtaining public key from certificate
body: <p>I'm trying to obtain the public key of a Certificate using the method:</p>
  
  <pre><code>FileInputStream fin = new FileInputStream("PathToCertificate");
  CertificateFactory f = CertificateFactory.getInstance("X.509");
  X509Certificate certificate = (X509Certificate)f.generateCertificate(fin);
  PublicKey pk = certificate.getPublicKey();
  </code></pre>
  
  <p>but I receive the following error:</p>
  
  <pre><code>Exception in thread "main" java.lang.ClassCastException: sun.security.x509.X509CertImpl cannot be cast to codec.x509.X509Certificate
          at sergas_testcertificates.Main.main(Main.java:54)
  </code></pre>
  
  <p>Does anyone know what this error is about?</p>
  
  <p>Thanks in advance</p>