Class PEMFileRSAPrivateKeySupplier

  • All Implemented Interfaces:
    KeySupplier<RSAPrivateKey>

    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

    • Constructor Detail

      • PEMFileRSAPrivateKeySupplier

        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.

        Parameters:
        inputStream - the path to the RSA private key
        passphraseCharacters - the passphrase of the private key, optional
    • Method Detail

      • supplyKey

        public Optional<RSAPrivateKey> supplyKey​(@Nonnull
                                                 String ignored)
        Get the key from the file.
        Specified by:
        supplyKey in interface KeySupplier<RSAPrivateKey>
        Parameters:
        ignored - this parameter is ignored. The key returned is always the same, the one from the file.
        Returns:
        an Optional for the key
      • supplyKey

        @Nonnull
        public Optional<RSAPrivateKey> supplyKey()
        Get the key from the file.
        Returns:
        an Optional for the key