code: private static Cipher initializeCipherBasedOnServicePublicKey(final PublicKey publicKey,
                                                                    final RegisteredService registeredService) {
          try {
              LOGGER.debug("Using service [{}] public key [{}] to initialize the cipher", registeredService.getServiceId(),
                  registeredService.getPublicKey());
  
              val cipher = Cipher.getInstance(publicKey.getAlgorithm());
              cipher.init(Cipher.ENCRYPT_MODE, publicKey);
              LOGGER.debug("Initialized cipher in encrypt-mode via the public key algorithm [{}] for service [{}]",
                  publicKey.getAlgorithm(), registeredService.getServiceId());
              return cipher;
          } catch (final Exception e) {
              LOGGER.warn("Cipher could not be initialized for service [{}]. Error [{}]",
                  registeredService, e.getMessage());
          }
          return null;
      }
docs: Initialize cipher based on service public key.
  
  @param publicKey         the public key
  @param registeredService the registered service
  @return the false if no public key is found
  or if cipher cannot be initialized, etc.