Package org.apache.tomcat.util.net.jsse
Class PEMFile
- java.lang.Object
-
- org.apache.tomcat.util.net.jsse.PEMFile
-
public class PEMFile extends java.lang.ObjectRFC 1421 PEM file containing X509 certificates or private keys.
-
-
Constructor Summary
Constructors Constructor Description PEMFile(java.lang.String filename)Construct a PEMFile from the given file without a password.PEMFile(java.lang.String filename, java.io.InputStream fileStream, java.lang.String password, java.lang.String keyAlgorithm)Construct a PEMFile from the given input stream with the given password and key algorithm.PEMFile(java.lang.String filename, java.io.InputStream fileStream, java.lang.String password, java.lang.String passwordFilename, java.io.InputStream passwordFileStream, java.lang.String keyAlgorithm)Construct a PEMFile from the given input stream with the given password and key algorithm.PEMFile(java.lang.String filename, java.lang.String password)Construct a PEMFile from the given file with the given password.PEMFile(java.lang.String filename, java.lang.String password, java.lang.String keyAlgorithm)Construct a PEMFile from the given file with the given password and key algorithm.PEMFile(java.lang.String filename, java.lang.String password, java.lang.String passwordFilename, java.lang.String keyAlgorithm)Construct a PEMFile from the given file with the password read from a separate file.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<java.security.cert.X509Certificate>getCertificates()Returns the list of X509 certificates loaded from this PEM file.java.security.PrivateKeygetPrivateKey()Returns the private key loaded from this PEM file.static java.lang.StringtoPEM(java.security.cert.X509Certificate certificate)Converts an X509 certificate to PEM format.
-
-
-
Constructor Detail
-
PEMFile
public PEMFile(java.lang.String filename) throws java.io.IOException, java.security.GeneralSecurityExceptionConstruct a PEMFile from the given file without a password.- Parameters:
filename- The path to the PEM file- Throws:
java.io.IOException- If the file cannot be readjava.security.GeneralSecurityException- If the file cannot be parsed
-
PEMFile
public PEMFile(java.lang.String filename, java.lang.String password) throws java.io.IOException, java.security.GeneralSecurityExceptionConstruct 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:
java.io.IOException- If the file cannot be readjava.security.GeneralSecurityException- If the file cannot be parsed
-
PEMFile
public PEMFile(java.lang.String filename, java.lang.String password, java.lang.String keyAlgorithm) throws java.io.IOException, java.security.GeneralSecurityExceptionConstruct 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:
java.io.IOException- If the file cannot be readjava.security.GeneralSecurityException- If the file cannot be parsed
-
PEMFile
public PEMFile(java.lang.String filename, java.lang.String password, java.lang.String passwordFilename, java.lang.String keyAlgorithm) throws java.io.IOException, java.security.GeneralSecurityExceptionConstruct 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:
java.io.IOException- If the file cannot be readjava.security.GeneralSecurityException- If the file cannot be parsed
-
PEMFile
public PEMFile(java.lang.String filename, java.io.InputStream fileStream, java.lang.String password, java.lang.String keyAlgorithm) throws java.io.IOException, java.security.GeneralSecurityExceptionConstruct 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:
java.io.IOException- If the stream cannot be readjava.security.GeneralSecurityException- If the data cannot be parsed
-
PEMFile
public PEMFile(java.lang.String filename, java.io.InputStream fileStream, java.lang.String password, java.lang.String passwordFilename, java.io.InputStream passwordFileStream, java.lang.String keyAlgorithm) throws java.io.IOException, java.security.GeneralSecurityExceptionConstruct 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:
java.io.IOException- if input can't be read.java.security.GeneralSecurityException- if input can't be parsed/loaded.
-
-
Method Detail
-
toPEM
public static java.lang.String toPEM(java.security.cert.X509Certificate certificate) throws java.security.cert.CertificateEncodingExceptionConverts an X509 certificate to PEM format.- Parameters:
certificate- The certificate to convert- Returns:
- The PEM-encoded certificate string
- Throws:
java.security.cert.CertificateEncodingException- If the certificate cannot be encoded
-
getCertificates
public java.util.List<java.security.cert.X509Certificate> getCertificates()
Returns the list of X509 certificates loaded from this PEM file.- Returns:
- the list of X509 certificates
-
getPrivateKey
public java.security.PrivateKey getPrivateKey()
Returns the private key loaded from this PEM file.- Returns:
- the private key, or null if no private key was loaded
-
-