/** * Get a Private Key from the string. * * @return Private key * @throws IOException if error reading PEM string. * @throws InvalidKeySpecException if PKCS#1 key spec unavailable. */ public PrivateKey getPrivateKey() throws IOException, InvalidKeySpecException { InputStream keyInputStream = new ByteArrayInputStream( keyPemString.getBytes(StringUtils.UTF8)); return PEM.readPrivateKey(keyInputStream); } }
/** * Returns the first private key that is found from the input stream of a * PEM file. * * @param is input stream of PEM data. * @return PrivateKey found in PEM. * @throws InvalidKeySpecException if failed to convert the DER bytes into a * private key. * @throws IllegalArgumentException if no private key is found. * @throws IOException if PEM could not be read. */ public static PrivateKey readPrivateKey(InputStream is) throws InvalidKeySpecException, IOException { List<PEMObject> objects = readPEMObjects(is); for (PEMObject object : objects) { switch (object.getPEMObjectType()) { case PRIVATE_KEY_PKCS1: return RSA.privateKeyFromPKCS1(object.getDerBytes()); default: break; } } throw new IllegalArgumentException("Found no private key"); }
/** * Returns the first private key that is found from the input stream of a * PEM file. * * @param is input stream of PEM data. * @return PrivateKey found in PEM. * @throws InvalidKeySpecException if failed to convert the DER bytes into a * private key. * @throws IllegalArgumentException if no private key is found. * @throws IOException if PEM could not be read. */ public static PrivateKey readPrivateKey(InputStream is) throws InvalidKeySpecException, IOException { List<PEMObject> objects = readPEMObjects(is); for (PEMObject object : objects) { switch (object.getPEMObjectType()) { case PRIVATE_KEY_PKCS1: return RSA.privateKeyFromPKCS1(object.getDerBytes()); default: break; } } throw new IllegalArgumentException("Found no private key"); }
/** * Get a Private Key from the string. * * @return Private key * @throws IOException if error reading PEM string. * @throws InvalidKeySpecException if PKCS#1 key spec unavailable. */ public PrivateKey getPrivateKey() throws IOException, InvalidKeySpecException { InputStream keyInputStream = new ByteArrayInputStream( keyPemString.getBytes(StringUtils.UTF8)); return PEM.readPrivateKey(keyInputStream); } }