/** * Decodes an encoded private key in either PKCS#8 or OpenSSL "traditional" format in either DER or PEM encoding. Keys * from the following asymmetric algorithms are supported: * * <ul> * <li>DSA</li> * <li>RSA</li> * <li>Elliptic curve</li> * </ul> * * @param encodedKey Encoded private key data. * * @return Private key. * * @throws EncodingException on key encoding errors. */ public static PrivateKey decodePrivateKey(final byte[] encodedKey) throws EncodingException { return decodePrivateKey(encodedKey, null); }
/** {@inheritDoc} */ @Override @Nullable protected PrivateKey getPrivateKey() { if (null == privateKey) { return null; } return KeyPairUtil.decodePrivateKey(privateKey, getPrivateKeyPassword()); }
@Override public PrivateKey newInstance() throws EncodingException { return KeyPairUtil.decodePrivateKey(PemUtil.decode(encodedKey)); } }
/** * Reads an encoded private key from an input stream. Both PKCS#8 and OpenSSL "traditional" formats are supported in * DER or PEM encoding. See {@link #decodePrivateKey(byte[])} for supported asymmetric algorithms. The {@link * InputStream} parameter is closed by this method. * * @param in Input stream containing private key data. * * @return Private key. * * @throws EncodingException on key encoding errors. * @throws StreamException on IO errors reading data from file. */ public static PrivateKey readPrivateKey(final InputStream in) throws EncodingException, StreamException { return decodePrivateKey(StreamUtil.readAll(in)); }
/** * Reads an encrypted private key from an input stream. Both PKCS#8 and OpenSSL "traditional" formats are supported in * DER or PEM encoding. See {@link #decodePrivateKey(byte[])} for supported asymmetric algorithms. The {@link * InputStream} parameter is closed by this method. * * @param in Input stream containing private key data. * @param password Password used to encrypt private key. * * @return Private key. * * @throws EncodingException on key encoding errors. * @throws StreamException on IO errors. */ public static PrivateKey readPrivateKey(final InputStream in, final char[] password) throws EncodingException, StreamException { return decodePrivateKey(StreamUtil.readAll(in), password); }
/** {@inheritDoc} */ @Override @Nullable protected PrivateKey getPrivateKey() { if (null == getPrivateKeyInfo()) { return null; } return KeyPairUtil.decodePrivateKey(getPrivateKeyInfo(), getPrivateKeyPassword()); }