Class PEMFile
java.lang.Object
org.apache.tomcat.util.net.jsse.PEMFile
RFC 1421 PEM file containing X509 certificates or private keys.
-
Constructor Summary
ConstructorsConstructorDescriptionConstruct a PEMFile from the given file without a password.PEMFile(String filename, InputStream fileStream, String password, String keyAlgorithm) Construct a PEMFile from the given input stream with the given password and key algorithm.PEMFile(String filename, InputStream fileStream, String password, String passwordFilename, InputStream passwordFileStream, String keyAlgorithm) Construct a PEMFile from the given input stream with the given password and key algorithm.Construct a PEMFile from the given file with the given password.Construct a PEMFile from the given file with the given password and key algorithm.Construct a PEMFile from the given file with the password read from a separate file. -
Method Summary
Modifier and TypeMethodDescriptionReturns the list of X509 certificates loaded from this PEM file.Returns the private key loaded from this PEM file.static StringtoPEM(X509Certificate certificate) Converts an X509 certificate to PEM format.
-
Constructor Details
-
PEMFile
Construct a PEMFile from the given file without a password.- Parameters:
filename- The path to the PEM file- Throws:
IOException- If the file cannot be readGeneralSecurityException- If the file cannot be parsed
-
PEMFile
Construct a PEMFile from the given file with the given password.- Parameters:
filename- The path to the PEM filepassword- The password to decrypt any encrypted private key- Throws:
IOException- If the file cannot be readGeneralSecurityException- If the file cannot be parsed
-
PEMFile
public PEMFile(String filename, String password, String keyAlgorithm) throws IOException, GeneralSecurityException Construct a PEMFile from the given file with the given password and key algorithm.- Parameters:
filename- The path to the PEM filepassword- The password to decrypt any encrypted private keykeyAlgorithm- The key algorithm, or null to auto-detect- Throws:
IOException- If the file cannot be readGeneralSecurityException- If the file cannot be parsed
-
PEMFile
public PEMFile(String filename, String password, String passwordFilename, String keyAlgorithm) throws IOException, GeneralSecurityException Construct a PEMFile from the given file with the password read from a separate file.- Parameters:
filename- The path to the PEM filepassword- The password to decrypt any encrypted private keypasswordFilename- The path to the file containing the passwordkeyAlgorithm- The key algorithm, or null to auto-detect- Throws:
IOException- If the file cannot be readGeneralSecurityException- If the file cannot be parsed
-
PEMFile
public PEMFile(String filename, InputStream fileStream, String password, String keyAlgorithm) throws IOException, GeneralSecurityException Construct a PEMFile from the given input stream with the given password and key algorithm.- Parameters:
filename- The filename to mention in error messagesfileStream- The input stream containing the PEM datapassword- The password to decrypt any encrypted private keykeyAlgorithm- The key algorithm, or null to auto-detect- Throws:
IOException- If the stream cannot be readGeneralSecurityException- If the data cannot be parsed
-
PEMFile
public PEMFile(String filename, InputStream fileStream, String password, String passwordFilename, InputStream passwordFileStream, String keyAlgorithm) throws IOException, GeneralSecurityException Construct a PEMFile from the given input stream with the given password and key algorithm.- Parameters:
filename- the filename to mention in error messages, not used for anything else.fileStream- the stream containing the pem(s).password- password to load the pem objects.passwordFilename- the password filename to mention in error messages, not used for anything else.passwordFileStream- stream containing the password to load the pem objects.keyAlgorithm- the algorithm to help to know how to load the objects (guessed if null).- Throws:
IOException- if input can't be read.GeneralSecurityException- if input can't be parsed/loaded.
-
-
Method Details
-
toPEM
Converts an X509 certificate to PEM format.- Parameters:
certificate- The certificate to convert- Returns:
- The PEM-encoded certificate string
- Throws:
CertificateEncodingException- If the certificate cannot be encoded
-
getCertificates
Returns the list of X509 certificates loaded from this PEM file.- Returns:
- the list of X509 certificates
-
getPrivateKey
Returns the private key loaded from this PEM file.- Returns:
- the private key, or null if no private key was loaded
-