Class KeyUtil
java.lang.Object
org.graylog2.plugin.inputs.transports.util.KeyUtil
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic FilegeneratePKCS8FromPrivateKey(Path tmpDir, char[] password, PrivateKey key) Build a password-encrypted PKCS8 private key and write it to a PEM file in the temp directory.static KeyManager[]initKeyStore(File tlsKeyFile, File tlsCertFile, String tlsKeyPassword) static Collection<? extends Certificate>loadCertificates(Path certificatePath) protected static PrivateKeyloadPrivateKey(File file, String password) static X509Certificate[]loadX509Certificates(Path certificatePath) static PrivateKeyprivateKeyFromFile(String password, File keyFile) Obtain a private key from a PKS8 PEM file, which is optionally password-protected.static X509CertificatereadCertificate(Path path) static PrivateKeyreadPrivateKey(Path path)
-
Constructor Details
-
KeyUtil
public KeyUtil()
-
-
Method Details
-
loadX509Certificates
public static X509Certificate[] loadX509Certificates(Path certificatePath) throws CertificateException, IOException - Throws:
CertificateExceptionIOException
-
loadCertificates
public static Collection<? extends Certificate> loadCertificates(Path certificatePath) throws CertificateException, IOException - Throws:
CertificateExceptionIOException
-
initKeyStore
public static KeyManager[] initKeyStore(File tlsKeyFile, File tlsCertFile, String tlsKeyPassword) throws IOException, GeneralSecurityException - Throws:
IOExceptionGeneralSecurityException
-
loadPrivateKey
protected static PrivateKey loadPrivateKey(File file, String password) throws IOException, GeneralSecurityException - Throws:
IOExceptionGeneralSecurityException
-
readCertificate
- Throws:
IOException
-
readPrivateKey
- Throws:
IOException
-
generatePKCS8FromPrivateKey
public static File generatePKCS8FromPrivateKey(Path tmpDir, char[] password, PrivateKey key) throws GeneralSecurityException Build a password-encrypted PKCS8 private key and write it to a PEM file in the temp directory. Caller is responsible for ensuring that the temp directory is writable. The file will be deleted when the VM exits.- Parameters:
tmpDir- path to directory in which to create thepassword- to protect the keykey- encrypt this key- Returns:
- PEM file
- Throws:
GeneralSecurityException
-
privateKeyFromFile
public static PrivateKey privateKeyFromFile(String password, File keyFile) throws IOException, org.bouncycastle.pkcs.PKCSException, org.bouncycastle.operator.OperatorCreationException Obtain a private key from a PKS8 PEM file, which is optionally password-protected.- Parameters:
password- password to decrypt the file - it may be null or empty in case of an unencrypted filekeyFile- the key file- Returns:
- the corresponding private key
- Throws:
IOExceptionorg.bouncycastle.pkcs.PKCSExceptionorg.bouncycastle.operator.OperatorCreationException
-