title: Obtaining public key from SubjectPublicKeyInfo
body: <p>I'm trying to get the public key from a SubjectPublicKeyInfo.However when I try:</p>
  
  <pre><code>PublicKey publicKey = k.generatePublic(keypsec);
  
  byte[] encoded=publicKey.getEncoded();
  SubjectPublicKeyInfo subPkInfo2 = new SubjectPublicKeyInfo(rsaEncryption, encoded);     
  RSAPublicKeyStructure  pubKey = new RSAPublicKeyStructure((ASN1Sequence)subPkInfo2.getPublicKey());
  </code></pre>
  
  <p>It throws this </p>
  
  <pre><code>java.lang.IllegalArgumentException: illegal object in getInstance: org.bouncycastle.asn1.DERSequence
      at org.bouncycastle.asn1.DERInteger.getInstance(DERInteger.java:37)
      at org.bouncycastle.asn1.x509.RSAPublicKeyStructure.&lt;init&gt;(RSAPublicKeyStructure.java:63)
  </code></pre>
  
  <p>Any ideas? I've tried PubliKeyFactory but it simply calls the last line.</p>