@ThreadSafety(level=NOT_THREADSAFE) public final class PKCS8PEMFileReader extends java.lang.Object implements java.io.Closeable
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
BEGIN_PRIVATE_KEY_HEADER
The header string that should appear on a line by itself before the
base64-encoded representation of the bytes that comprise a PKCS #8 private
key.
|
static java.lang.String |
BEGIN_RSA_PRIVATE_KEY_HEADER
An alternative begin header string that may appear on a line by itself for
cases in which the certificate uses an RSA key pair.
|
static java.lang.String |
END_PRIVATE_KEY_FOOTER
The footer string that should appear on a line by itself after the
base64-encoded representation of the bytes that comprise a PKCS #8 private
key.
|
static java.lang.String |
END_RSA_PRIVATE_KEY_FOOTER
An alternative end footer string that may appear on a line by itself for
cases in which the certificate uses an RSA key pair.
|
Constructor and Description |
---|
PKCS8PEMFileReader(java.io.File pemFile)
Creates a new PKCS #8 PEM file reader that will read private key
information from the specified file.
|
PKCS8PEMFileReader(java.io.InputStream inputStream)
Creates a new PKCS #8 PEM file reader that will read private key
information from the provided input stream.
|
PKCS8PEMFileReader(java.lang.String pemFilePath)
Creates a new PKCS #8 PEM file reader that will read private key
information from the specified file.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this PKCS #8 PEM file reader.
|
PKCS8PrivateKey |
readPrivateKey()
Reads the next private key from the PEM file.
|
@NotNull public static final java.lang.String BEGIN_PRIVATE_KEY_HEADER
@NotNull public static final java.lang.String BEGIN_RSA_PRIVATE_KEY_HEADER
@NotNull public static final java.lang.String END_PRIVATE_KEY_FOOTER
@NotNull public static final java.lang.String END_RSA_PRIVATE_KEY_FOOTER
public PKCS8PEMFileReader(@NotNull java.lang.String pemFilePath) throws java.io.IOException
pemFilePath
- The path to the PEM file from which the private key
should be read. This must not be null
and the
file must exist.java.io.IOException
- If a problem occurs while attempting to open the file
for reading.public PKCS8PEMFileReader(@NotNull java.io.File pemFile) throws java.io.IOException
pemFile
- The PEM file from which the private key should be read.
This must not be null
and the file must
exist.java.io.IOException
- If a problem occurs while attempting to open the file
for reading.public PKCS8PEMFileReader(@NotNull java.io.InputStream inputStream)
inputStream
- The input stream from which the private key should
be read. This must not be null
and it must be
open for reading.@Nullable public PKCS8PrivateKey readPrivateKey() throws java.io.IOException, CertException
null
if the end of the
file has been reached.java.io.IOException
- If a problem occurs while trying to read data from
the PEM file.CertException
- If a problem occurs while trying to interpret data
read from the PEM file as a PKCS #8 private key.public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
- If a problem is encountered while attempting to close
the reader.