public class PEMFileRSAPrivateKeySupplier extends Object implements KeySupplier<RSAPrivateKey>
An implementation of KeySupplier
that supplies a RSA private key from a PEM file.
Supports PKCS#8 (starts with ‘—–BEGIN PRIVATE KEY—–’ tag), PKCS#8 encrypted key (starts
with ‘—–BEGIN ENCRYPTED PRIVATE KEY—–’ tag) and PKCS#1 (i.e., starts with ‘—–BEGIN RSA
PRIVATE KEY—–’ tag) format.
Example commands that can be used to generate a 2048 bits RSA private key:
$ openssl genrsa -out privateKey 2048
$ ssh-keygen -t rsa -b 2048
Modifier and Type | Class and Description |
---|---|
static class |
PEMFileRSAPrivateKeySupplier.PEMFileRSAPrivateKeySupplierException
An exception in the
PEMFileRSAPrivateKeySupplier . |
Constructor and Description |
---|
PEMFileRSAPrivateKeySupplier(InputStream inputStream,
char[] passphraseCharacters)
Constructs a new file key supplier which reads the private key from the specified file.
|
Modifier and Type | Method and Description |
---|---|
Optional<RSAPrivateKey> |
supplyKey()
Get the key from the file.
|
Optional<RSAPrivateKey> |
supplyKey(String ignored)
Get the key from the file.
|
public PEMFileRSAPrivateKeySupplier(@Nonnull InputStream inputStream, @Nullable char[] passphraseCharacters)
Constructs a new file key supplier which reads the private key from the specified file. The provided stream will be closed by this supplier automatically.
inputStream
- the path to the RSA private keypassphraseCharacters
- the passphrase of the private key, optionalpublic Optional<RSAPrivateKey> supplyKey(@Nonnull String ignored)
Get the key from the file.
supplyKey
in interface KeySupplier<RSAPrivateKey>
ignored
- this parameter is ignored. The key returned is always the same, the one from
the file.@Nonnull public Optional<RSAPrivateKey> supplyKey()
Get the key from the file.
Copyright © 2016–2024. All rights reserved.