code: public byte[] encrypt(final String text, final KeyType keyType) throws EncryptionException {
        final Key key = keyType == KeyType.PRIVATE ? privateKey : publicKey;
  
        try {
           // get an RSA cipher object and print the provider
           final Cipher cipher = Cipher.getInstance(ALGORITHM);
           // encrypt the plain text using the public key
           cipher.init(Cipher.ENCRYPT_MODE, key);
           final byte[] cipherText = cipher.doFinal(text.getBytes(DEFAULT_CHARSET));
  
           return cipherText;
        } catch (NoSuchAlgorithmException | InvalidKeyException | NoSuchPaddingException | BadPaddingException | IllegalBlockSizeException e) {
           throw new EncryptionException("Unable to encrypt message: ", e);
        }
     }
docs: Encrypts the given message with the specified key type (either public or private).
  
  @param text
  The message to encrypt.
  @param keyType
  THe key type to be used.
  @return The encrypted message.
  @throws EncryptionException
  When it was not possible to encrypt the message.