Code example for X509EncodedKeySpec

0
      return null; 
    } 
     
    try { 
      KeyFactory fac = KeyFactory.getInstance("RSA");
      EncodedKeySpec spec = new X509EncodedKeySpec(publicKey);
      return fac.generatePublic(spec);
    } 
    catch (NoSuchAlgorithmException e) {
      throw new IllegalStateException(e);
    } 
    catch (InvalidKeySpecException e) {
      throw new IllegalStateException(e);
    } 
  } 
 
  /** 
   * Creates a private key from the PKCS#8-encoded value of the given bytes. 
   * 
   * @param privateKey The PKCS#8-encoded private key bytes.