This is an automated email from the ASF dual-hosted git repository.

bamaer pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hop.git


The following commit(s) were added to refs/heads/main by this push:
     new 229c25173e Fix#9207   PGP encrypt and decrypt file actions (#9319)
229c25173e is described below

commit 229c25173e5e41d75492aafb2e5dfdd9d4764f1c
Author: Lance <[email protected]>
AuthorDate: Fri Nov 6 16:51:18 2026 +0800

    Fix#9207   PGP encrypt and decrypt file actions (#9319)
    
    * Fix PGP encrypt and decrypt file actions
    
    Signed-off-by: leehaut <[email protected]>
    
    * Fix PGP encrypt and decrypt file actions
    
    Signed-off-by: leehaut <[email protected]>
    
    * Fix PGP encrypt and decrypt file actions
    
    Signed-off-by: leehaut <[email protected]>
    
    ---------
    
    Signed-off-by: leehaut <[email protected]>
---
 .../pages/workflow/actions/pgpdecryptfiles.adoc    |  12 +-
 .../pages/workflow/actions/pgpencryptfiles.adoc    |  17 +-
 .../pgpdecryptfiles/ActionPGPDecryptFiles.java     | 248 +++++++--------
 .../pgpencryptfiles/ActionPGPEncryptFiles.java     |  66 ++--
 .../ActionPGPEncryptFilesDialog.java               |  17 +-
 .../hop/workflow/actions/pgpencryptfiles/GPG.java  |  95 +++++-
 .../messages/messages_en_US.properties             |   1 +
 .../messages/messages_en_US.properties             |   4 +-
 .../ActionPGPEncryptFilesDialogTest.java           |   2 +
 .../pgpencryptfiles/ActionPGPEncryptFilesTest.java |  32 ++
 .../ActionPGPFilesBehaviorTest.java                | 207 +++++++++++++
 .../ActionPGPFilesConflictTest.java                | 343 +++++++++++++++++++++
 .../pgpencryptfiles/GpgArgumentPassingTest.java    |  44 +++
 .../actions/pgpencryptfiles/GpgCopyStub.java       | 130 ++++++++
 14 files changed, 1053 insertions(+), 165 deletions(-)

diff --git 
a/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/pgpdecryptfiles.adoc 
b/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/pgpdecryptfiles.adoc
index 1f15fc1573..6423c31a0e 100644
--- 
a/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/pgpdecryptfiles.adoc
+++ 
b/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/pgpdecryptfiles.adoc
@@ -58,7 +58,7 @@ GnuPG package must be installed in the runtime environment 
and encryption keys a
 |Specify Date time format|Whether or not to specify the date time format.
 |Date time format|The format of the date time.
 |Add date before extension|Before or after extension.
-|If destination file exists a|What to do when the destination file already 
exists. See the WARNING under <<Result>>.
+|If destination file exists a|What to do when the destination file already 
exists. *Delete source file* deletes the source and leaves the destination 
unchanged. *Move source file to folder* leaves the destination unchanged and 
moves the source into *Destination folder*. *Do nothing* leaves an existing 
file unchanged.
 
 * Do nothing (default)
 * Overwrite destination file
@@ -111,16 +111,16 @@ What this action passes on to the next action. See 
xref:workflow/action-results.
 * Success when at least x files decrypted: at least *Nr errors lesser than* 
files were decrypted, whatever the number of errors.
 * Success when number of errors lesser than: the number of errors is at most 
*Nr errors lesser than*. When an entry of the list brings the errors to that 
number and entries are left, the action stops and is false; when the last entry 
does, the action is still true.
 |False|The success condition is not met. A file or an entry of the list fails, 
and counts as an error, when its source doesn't exist, the passphrase is wrong, 
the file is not encrypted, or the destination file exists and *If destination 
file exists* is *Fail*. It is also false, before any file and whatever the 
success condition, when *If destination file exists* is *Move source file to 
folder* while *Destination folder* is empty, or doesn't exist and *Create 
folder* is unchecked. With *S [...]
-|Errors|The number of files and entries that failed. Inside a folder, when 
files are left after the one that breaks the success condition, that failure 
counts as two errors.
-|Result files|With *Add files to result files name*, a decrypted file that 
didn't exist yet in the destination is added unless *If destination file 
exists* is *Do nothing* (the default) or *Fail*: with the default, no file is 
added. When the destination file already exists, a file is added only with 
*Overwrite destination file* or *Create file with unique name*, and with *Move 
source file to folder* the moved source file is added. The result files of the 
previous action are kept.
+|Errors|The number of files and entries that failed. Inside a folder, the 
action stops once the success condition is broken, and that failure counts as 
one error. A *GPG location* that is empty or not found counts as 1 error, 
before any file: the action is false with *Success when all works fine* and 
*Success when at least x files decrypted*, and true with *Success when number 
of errors lesser than*.
+|Result files|With *Add files to result files name*, the decrypted file is 
added. That includes a file that did not exist yet, whatever *If destination 
file exists* says, because that option only applies when the destination 
already exists. When it does, the written file is added for *Overwrite 
destination file* and *Create file with unique name* (the new file). *Move 
source file to folder* adds the moved source, not the existing destination. 
*Delete source file*, *Do nothing* and *Fail* [...]
 |Result rows|Passed on unchanged.
-|Lines written|The number of files decrypted. A file left in place by *Do 
nothing*, deleted or moved is not counted. When the check of *Destination 
folder* (Move to folder) fails, or the action stops on the success condition 
between two entries of the list, the value of the previous action is passed on.
+|Lines written|The number of files decrypted. *Delete source file* counts the 
deleted source and does not write the destination. A source moved to a new name 
is not counted; overwriting or giving a unique name to a file that already 
exists in *Destination folder* counts that file. A file left in place by *Do 
nothing*, and a file rejected by *Fail* or by *If file exists in destination 
folder* set to *Fail*, is not counted. When the check of *Destination folder* 
(Move to folder) fails, or  [...]
 |===
 
 NOTE: The decrypted file keeps the name of the source file: `a.txt.gpg` 
becomes `a.txt.gpg` in the destination folder.
 
-NOTE: A *GPG location* that is empty or not found doesn't make the action 
false: the workflow stops with an error, and no hop from the action is followed.
+NOTE: A *GPG location* that is empty or not found counts as 1 error, before 
any file. The action is false with *Success when all works fine* and *Success 
when at least x files decrypted*, and true with *Success when number of errors 
lesser than* (the default limit is 10). When the action is false, the error hop 
is followed. The workflow itself keeps running.
 
-WARNING: *If destination file exists* doesn't always do what its name says. 
*Delete source file* deletes the existing destination file, not the source, and 
decrypts nothing. *Move source file to folder* moves the source file to 
*Destination folder* without decrypting it.
+NOTE: *Delete source file* deletes the source and leaves the existing 
destination unchanged. *Move source file to folder* leaves the existing 
destination unchanged and moves the source into *Destination folder*.
 
 NOTE: When the destination file exists, *Create file with unique name* writes 
the decrypted file under a new name, with the date and time added after the 
file name (for example `a.txt.gpg30102026_140548429`), and *Do nothing* keeps 
the existing file and doesn't decrypt the source.
diff --git 
a/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/pgpencryptfiles.adoc 
b/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/pgpencryptfiles.adoc
index b100e4463d..ee3aad2b32 100644
--- 
a/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/pgpencryptfiles.adoc
+++ 
b/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/pgpencryptfiles.adoc
@@ -37,13 +37,14 @@ GnuPG package must be installed in the runtime environment 
and encryption keys a
 |GPG location|The file path of the GnuPG executable (e.g. `/usr/bin/gpg`).
 |Use ASCII mode|Whether or not to use ASCII mode when encrypting.
 |Include Subfolders|Also processes the files in the subfolders of a source 
folder.
-|Copy previous results to args|Take the rows below from the result of the 
previous action instead of from the grid. The fields are read by position: 
action, file/folder source, wildcard, user ID, file/folder destination, and 
optionally signing key as a sixth field.
+|Copy previous results to args|Take the rows below from the result of the 
previous action instead of from the grid. The fields are read by position: 
action, file/folder source, wildcard, user ID, file/folder destination, and 
optionally signing key as a sixth field and passphrase as a seventh.
 |Action|Encrypt, Sign, Sign and Encrypt
 |File/Folder source|The file to encrypt, can be added to the Files/Folders 
list using Add.
 |File/Folder destination|The destination of the encrypted files.
 |Wildcard|A regex wildcard.
 |User ID|User ID of the key to encrypt to, passed to GnuPG as `-r`. Required 
for Encrypt and Sign and Encrypt, and not used by Sign.
 |Signing key|User ID of the key to sign with, passed to GnuPG as `-u`. Used by 
Sign and Sign and Encrypt; leave it empty to sign with the default key from the 
GnuPG configuration.
+|Passphrase|Passphrase of the signing key. Sent to GnuPG on standard input, 
never on the command line. Leave it empty when the key has no passphrase. 
Ignored by Encrypt.
 |Files/Folders|The files to encrypt.
 |===
 
@@ -61,7 +62,7 @@ GnuPG package must be installed in the runtime environment 
and encryption keys a
 |Specify Date time format|Whether or not to specify the date time format.
 |Date time format|The format of the date time.
 |Add date before extension|Before or after extension.
-|If destination file exists a|What to do when the destination file already 
exists. See the WARNING under <<Result>>.
+|If destination file exists a|What to do when the destination file already 
exists. *Delete source file* deletes the source and leaves the destination 
unchanged. *Move source file to folder* leaves the destination unchanged and 
moves the source into *Destination folder*. *Create file with unique name* 
writes a new file and leaves the existing one in place. *Do nothing* leaves an 
existing file unchanged.
 
 * Do nothing (default)
 * Overwrite destination file
@@ -113,17 +114,17 @@ What this action passes on to the next action. See 
xref:workflow/action-results.
 * Success when all works fine (default): no file failed. An empty 
Files/Folders list, no file matching the wildcard, or *Copy previous results to 
args* without previous result rows is also true.
 * Success when at least x files decrypted: at least *Nr errors lesser than* 
files were encrypted or signed, whatever the number of errors.
 * Success when number of errors lesser than: the number of errors is at most 
*Nr errors lesser than*. When an entry of the list brings the errors to that 
number and entries are left, the action stops and is false; when the last entry 
does, the action is still true.
-|False|The success condition is not met. A file or an entry of the list fails, 
and counts as an error, when its source doesn't exist, the destination folder 
doesn't exist and *Create destination folder* is unchecked, GnuPG fails (an 
unknown or empty *User ID*, a signing key that needs a passphrase), the 
destination file exists and *If destination file exists* is *Fail*, or a folder 
is the source while *Destination is a file* is checked. It is also false, 
before any file and whatever the  [...]
-|Errors|The number of files and entries that failed. Inside a folder, when 
files are left after the one that breaks the success condition, that failure 
counts as two errors. A *GPG location* that is empty or not found counts as 1 
error, before any file: the action is false with *Success when all works fine* 
and *Success when at least x files decrypted*, and true with *Success when 
number of errors lesser than*.
-|Result files|With *Add files to result files name*, an encrypted file that 
didn't exist yet in the destination is added unless *If destination file 
exists* is *Do nothing* (the default) or *Fail*: with the default, no file is 
added. When the destination file already exists, a file is added only with 
*Overwrite destination file* or *Create file with unique name*, and with *Move 
source file to folder* the moved source file is added. The result files of the 
previous action are kept.
+|False|The success condition is not met. A file or an entry of the list fails, 
and counts as an error, when its source doesn't exist, the destination folder 
doesn't exist and *Create destination folder* is unchecked, GnuPG fails (an 
unknown or empty *User ID*, a missing or wrong passphrase for a signing key 
that needs one), the destination file exists and *If destination file exists* 
is *Fail*, or a folder is the source while *Destination is a file* is checked. 
It is also false, before a [...]
+|Errors|The number of files and entries that failed. Inside a folder, the 
action stops once the success condition is broken, and that failure counts as 
one error. A *GPG location* that is empty or not found counts as 1 error, 
before any file: the action is false with *Success when all works fine* and 
*Success when at least x files decrypted*, and true with *Success when number 
of errors lesser than*.
+|Result files|With *Add files to result files name*, the encrypted or signed 
file is added. That includes a file that did not exist yet, whatever *If 
destination file exists* says, because that option only applies when the 
destination already exists. When it does, the written file is added for 
*Overwrite destination file* and *Create file with unique name* (the new file). 
*Move source file to folder* adds the moved source, not the existing 
destination. *Delete source file*, *Do nothing*  [...]
 |Result rows|Passed on unchanged.
-|Lines written|The number of files encrypted or signed. A file left in place 
by *Do nothing*, deleted or moved is not counted. When the check of 
*Destination folder* (Move to folder) fails, or the action stops on the success 
condition between two entries of the list, the value of the previous action is 
passed on.
+|Lines written|The number of files encrypted or signed. *Delete source file* 
counts the deleted source and does not write the destination. A source moved to 
a new name is not counted; overwriting or giving a unique name to a file that 
already exists in *Destination folder* counts that file. A file left in place 
by *Do nothing*, and a file rejected by *Fail* or by *If file exists in 
destination folder* set to *Fail*, is not counted. When the check of 
*Destination folder* (Move to folder)  [...]
 |===
 
 NOTE: The encrypted or signed file keeps the name of the source file: `a.txt` 
becomes `a.txt` in the destination folder, no extension is added.
 
-WARNING: *If destination file exists* doesn't always do what its name says. 
*Create file with unique name* builds a new name (the date and time added after 
the file name, for example `a.txt30102026_140920035`) but writes to the 
existing file, which is overwritten; the new name, which doesn't exist, is 
added to the result files. *Delete source file* deletes the existing 
destination file, not the source, and encrypts nothing. *Move source file to 
folder* moves the source file to *Destinati [...]
+NOTE: *Create file with unique name* adds the date and time after the file 
name (for example `a.txt30102026_140920035`) and writes the encrypted or signed 
data there. The existing file is left as it is.
 
-NOTE: The action has no passphrase option: for *Sign* and *Sign and encrypt*, 
GnuPG must be able to use the signing key without asking for one, for example a 
key without passphrase or a passphrase already held by `gpg-agent`. Otherwise 
the file fails.
+NOTE: For *Sign* and *Sign and encrypt*, put the signing key's passphrase in 
*Passphrase* when the key has one. It is handed to GnuPG on standard input 
together with `--pinentry-mode loopback`. An empty passphrase asks GnuPG to 
sign without one.
 
 NOTE: With *Include Subfolders* and *Do not keep folder structure* unchecked, 
a file in a subfolder is written to the same subfolder in the destination. 
GnuPG doesn't create that subfolder, so the file fails when it doesn't exist.
diff --git 
a/plugins/actions/pgpfiles/src/main/java/org/apache/hop/workflow/actions/pgpdecryptfiles/ActionPGPDecryptFiles.java
 
b/plugins/actions/pgpfiles/src/main/java/org/apache/hop/workflow/actions/pgpdecryptfiles/ActionPGPDecryptFiles.java
index 82c0407b14..ca8a594b53 100644
--- 
a/plugins/actions/pgpfiles/src/main/java/org/apache/hop/workflow/actions/pgpdecryptfiles/ActionPGPDecryptFiles.java
+++ 
b/plugins/actions/pgpfiles/src/main/java/org/apache/hop/workflow/actions/pgpdecryptfiles/ActionPGPDecryptFiles.java
@@ -238,133 +238,138 @@ public class ActionPGPDecryptFiles extends ActionBase 
implements Cloneable, IAct
       }
     }
 
-    gpg = new GPG(resolve(gpgLocation), getLogChannel(), getVariables());
+    try {
+      gpg = new GPG(resolve(gpgLocation), getLogChannel(), getVariables());
 
-    if (argFromPrevious && isDetailed()) {
-      logDetailed(
-          BaseMessages.getString(
-              PKG,
-              "ActionPGPDecryptFiles.Log.ArgFromPrevious.Found",
-              (rows != null ? rows.size() : 0) + ""));
-    }
-    if (argFromPrevious && rows != null) {
-      for (RowMetaAndData row : rows) {
-        // Success condition broken?
-        if (successConditionBroken) {
-          if (!successConditionBrokenExit) {
-            logError(
-                BaseMessages.getString(
-                    PKG,
-                    
CONST_ACTION_PGP_DECRYPT_FILES_ERROR_SUCCESS_CONDITION_BROKEN,
-                    "" + nrErrors));
-            successConditionBrokenExit = true;
+      if (argFromPrevious && isDetailed()) {
+        logDetailed(
+            BaseMessages.getString(
+                PKG,
+                "ActionPGPDecryptFiles.Log.ArgFromPrevious.Found",
+                (rows != null ? rows.size() : 0) + ""));
+      }
+      if (argFromPrevious && rows != null) {
+        for (RowMetaAndData row : rows) {
+          // Success condition broken?
+          if (successConditionBroken) {
+            if (!successConditionBrokenExit) {
+              logError(
+                  BaseMessages.getString(
+                      PKG,
+                      
CONST_ACTION_PGP_DECRYPT_FILES_ERROR_SUCCESS_CONDITION_BROKEN,
+                      "" + nrErrors));
+              successConditionBrokenExit = true;
+            }
+            result.setNrErrors(nrErrors);
+            displayResults();
+            return result;
           }
-          result.setNrErrors(nrErrors);
-          displayResults();
-          return result;
-        }
 
-        resultRow = row;
+          resultRow = row;
 
-        // Get source and destination file names, also wildcard
-        String vSourceFileFolderPrevious = resultRow.getString(0, null);
-        String vWildcardPrevious = resolve(resultRow.getString(1, null));
-        String vPassPhrasePrevious =
-            Encr.decryptPasswordOptionallyEncrypted(resultRow.getString(2, 
null));
-        String vDestinationFileFolderPrevious = resultRow.getString(3, null);
+          // Get source and destination file names, also wildcard
+          String vSourceFileFolderPrevious = resultRow.getString(0, null);
+          String vWildcardPrevious = resolve(resultRow.getString(1, null));
+          String vPassPhrasePrevious =
+              Encr.decryptPasswordOptionallyEncrypted(resultRow.getString(2, 
null));
+          String vDestinationFileFolderPrevious = resultRow.getString(3, null);
 
-        if (!Utils.isEmpty(vSourceFileFolderPrevious)
-            && !Utils.isEmpty(vDestinationFileFolderPrevious)) {
-          if (isDetailed()) {
-            logDetailed(
-                BaseMessages.getString(
-                    PKG,
-                    "ActionPGPDecryptFiles.Log.ProcessingRow",
-                    vSourceFileFolderPrevious,
-                    vDestinationFileFolderPrevious,
-                    vWildcardPrevious));
-          }
+          if (!Utils.isEmpty(vSourceFileFolderPrevious)
+              && !Utils.isEmpty(vDestinationFileFolderPrevious)) {
+            if (isDetailed()) {
+              logDetailed(
+                  BaseMessages.getString(
+                      PKG,
+                      "ActionPGPDecryptFiles.Log.ProcessingRow",
+                      vSourceFileFolderPrevious,
+                      vDestinationFileFolderPrevious,
+                      vWildcardPrevious));
+            }
 
-          if (!processFileFolder(
-              vSourceFileFolderPrevious,
-              vPassPhrasePrevious,
-              vDestinationFileFolderPrevious,
-              vWildcardPrevious,
-              parentWorkflow,
-              result,
-              moveToFolder)) {
-            // The move process fail
-            // Update Errors
-            updateErrors();
-          }
-        } else {
-          if (isDetailed()) {
-            logDetailed(
-                BaseMessages.getString(
-                    PKG,
-                    "ActionPGPDecryptFiles.Log.IgnoringRow",
-                    vSourceFileFolderPrevious,
-                    vDestinationFileFolderPrevious,
-                    vWildcardPrevious));
+            if (!processFileFolder(
+                vSourceFileFolderPrevious,
+                vPassPhrasePrevious,
+                vDestinationFileFolderPrevious,
+                vWildcardPrevious,
+                parentWorkflow,
+                result,
+                moveToFolder)) {
+              // The move process fail
+              // Update Errors
+              updateErrors();
+            }
+          } else {
+            if (isDetailed()) {
+              logDetailed(
+                  BaseMessages.getString(
+                      PKG,
+                      "ActionPGPDecryptFiles.Log.IgnoringRow",
+                      vSourceFileFolderPrevious,
+                      vDestinationFileFolderPrevious,
+                      vWildcardPrevious));
+            }
           }
         }
-      }
-    } else if (!filesToDecrypt.isEmpty()) {
-      for (FileToDecrypt fileToDecrypt : filesToDecrypt) {
-        if (parentWorkflow.isStopped()) {
-          break;
-        }
-        // Success condition broken?
-        if (successConditionBroken) {
-          if (!successConditionBrokenExit) {
-            logError(
-                BaseMessages.getString(
-                    PKG,
-                    
CONST_ACTION_PGP_DECRYPT_FILES_ERROR_SUCCESS_CONDITION_BROKEN,
-                    "" + nrErrors));
-            successConditionBrokenExit = true;
+      } else if (!filesToDecrypt.isEmpty()) {
+        for (FileToDecrypt fileToDecrypt : filesToDecrypt) {
+          if (parentWorkflow.isStopped()) {
+            break;
           }
-          result.setNrErrors(nrErrors);
-          displayResults();
-          return result;
-        }
-
-        if (!Utils.isEmpty(fileToDecrypt.getSourceFileFolder())
-            && !Utils.isEmpty(fileToDecrypt.getDestinationFileFolder())) {
-          // ok we can process this file/folder
-          if (isDetailed()) {
-            logDetailed(
-                BaseMessages.getString(
-                    PKG,
-                    "ActionPGPDecryptFiles.Log.ProcessingRow",
-                    fileToDecrypt.getSourceFileFolder(),
-                    fileToDecrypt.getDestinationFileFolder(),
-                    fileToDecrypt.getWildcard()));
+          // Success condition broken?
+          if (successConditionBroken) {
+            if (!successConditionBrokenExit) {
+              logError(
+                  BaseMessages.getString(
+                      PKG,
+                      
CONST_ACTION_PGP_DECRYPT_FILES_ERROR_SUCCESS_CONDITION_BROKEN,
+                      "" + nrErrors));
+              successConditionBrokenExit = true;
+            }
+            result.setNrErrors(nrErrors);
+            displayResults();
+            return result;
           }
 
-          if (!processFileFolder(
-              fileToDecrypt.getSourceFileFolder(),
-              
Encr.decryptPasswordOptionallyEncrypted(resolve(fileToDecrypt.getPassphrase())),
-              fileToDecrypt.getDestinationFileFolder(),
-              fileToDecrypt.getWildcard(),
-              parentWorkflow,
-              result,
-              moveToFolder)) {
-            // Update Errors
-            updateErrors();
-          }
-        } else {
-          if (isDetailed()) {
-            logDetailed(
-                BaseMessages.getString(
-                    PKG,
-                    "ActionPGPDecryptFiles.Log.IgnoringRow",
-                    fileToDecrypt.getSourceFileFolder(),
-                    fileToDecrypt.getDestinationFileFolder(),
-                    fileToDecrypt.getWildcard()));
+          if (!Utils.isEmpty(fileToDecrypt.getSourceFileFolder())
+              && !Utils.isEmpty(fileToDecrypt.getDestinationFileFolder())) {
+            // ok we can process this file/folder
+            if (isDetailed()) {
+              logDetailed(
+                  BaseMessages.getString(
+                      PKG,
+                      "ActionPGPDecryptFiles.Log.ProcessingRow",
+                      fileToDecrypt.getSourceFileFolder(),
+                      fileToDecrypt.getDestinationFileFolder(),
+                      fileToDecrypt.getWildcard()));
+            }
+
+            if (!processFileFolder(
+                fileToDecrypt.getSourceFileFolder(),
+                
Encr.decryptPasswordOptionallyEncrypted(resolve(fileToDecrypt.getPassphrase())),
+                fileToDecrypt.getDestinationFileFolder(),
+                fileToDecrypt.getWildcard(),
+                parentWorkflow,
+                result,
+                moveToFolder)) {
+              // Update Errors
+              updateErrors();
+            }
+          } else {
+            if (isDetailed()) {
+              logDetailed(
+                  BaseMessages.getString(
+                      PKG,
+                      "ActionPGPDecryptFiles.Log.IgnoringRow",
+                      fileToDecrypt.getSourceFileFolder(),
+                      fileToDecrypt.getDestinationFileFolder(),
+                      fileToDecrypt.getWildcard()));
+            }
           }
         }
       }
+    } catch (Exception e) {
+      updateErrors();
+      logError(BaseMessages.getString(PKG, "ActionPGPDecryptFiles.Error", 
e.getMessage()));
     }
 
     // Success Condition
@@ -560,7 +565,7 @@ public class ActionPGPDecryptFiles extends ActionBase 
implements Cloneable, IAct
                               "" + nrErrors));
                       successConditionBrokenExit = true;
                     }
-                    return false;
+                    break;
                   }
                   // Fetch files in list one after one ...
                   currentFile = fileObjects[j];
@@ -662,10 +667,8 @@ public class ActionPGPDecryptFiles extends ActionBase 
implements Cloneable, IAct
                   destinationFileName.getName().toString()));
         }
 
-        // add filename to result filename
-        if (addResultFilenames
-            && !ifFileExists.equals("fail")
-            && !ifFileExists.equals(CONST_DO_NOTHING)) {
+        // The destination did not exist, so the option for an existing file 
does not apply.
+        if (addResultFilenames) {
           addFileToResultFilenames(destinationFileName.toString(), result, 
parentWorkflow);
         }
 
@@ -737,14 +740,15 @@ public class ActionPGPDecryptFiles extends ActionBase 
implements Cloneable, IAct
             updateSuccess();
           }
           case CONST_DELETE_FILE -> {
-            destinationFileName.delete();
+            sourceFileName.delete();
             if (isDetailed()) {
               logDetailed(
                   BaseMessages.getString(
                       PKG,
                       "ActionPGPDecryptFiles.Log.FileDeleted",
-                      destinationFileName.getName().toString()));
+                      sourceFileName.getName().toString()));
             }
+            updateSuccess();
           }
           case CONST_MOVE_FILE -> {
             String shortFilename = shortFileName;
@@ -775,7 +779,7 @@ public class ActionPGPDecryptFiles extends ActionBase 
implements Cloneable, IAct
 
               // add filename to result filename
               if (addResultFilenames
-                  && !ifFileExists.equals("fail")
+                  && !ifFileExists.equals(CONST_FAIL)
                   && !ifFileExists.equals(CONST_DO_NOTHING)) {
                 addFileToResultFilenames(destinationFile.toString(), result, 
parentWorkflow);
               }
@@ -794,7 +798,7 @@ public class ActionPGPDecryptFiles extends ActionBase 
implements Cloneable, IAct
 
                   // add filename to result filename
                   if (addResultFilenames
-                      && !ifFileExists.equals("fail")
+                      && !ifFileExists.equals(CONST_FAIL)
                       && !ifFileExists.equals(CONST_DO_NOTHING)) {
                     addFileToResultFilenames(destinationFile.toString(), 
result, parentWorkflow);
                   }
diff --git 
a/plugins/actions/pgpfiles/src/main/java/org/apache/hop/workflow/actions/pgpencryptfiles/ActionPGPEncryptFiles.java
 
b/plugins/actions/pgpfiles/src/main/java/org/apache/hop/workflow/actions/pgpencryptfiles/ActionPGPEncryptFiles.java
index 9e4340e8ef..cc35891c68 100644
--- 
a/plugins/actions/pgpfiles/src/main/java/org/apache/hop/workflow/actions/pgpencryptfiles/ActionPGPEncryptFiles.java
+++ 
b/plugins/actions/pgpfiles/src/main/java/org/apache/hop/workflow/actions/pgpencryptfiles/ActionPGPEncryptFiles.java
@@ -36,6 +36,7 @@ import org.apache.hop.core.Result;
 import org.apache.hop.core.ResultFile;
 import org.apache.hop.core.RowMetaAndData;
 import org.apache.hop.core.annotations.Action;
+import org.apache.hop.core.encryption.Encr;
 import org.apache.hop.core.exception.HopException;
 import org.apache.hop.core.exception.HopValueException;
 import org.apache.hop.core.util.Utils;
@@ -331,6 +332,7 @@ public class ActionPGPEncryptFiles extends ActionBase 
implements Cloneable, IAct
             vPgpFile.getSourceFileFolder(),
             vPgpFile.getUserId(),
             vPgpFile.getLocalUser(),
+            vPgpFile.getPassphrase(),
             vPgpFile.getDestinationFileFolder(),
             vPgpFile.getWildcard(),
             parentWorkflow,
@@ -390,11 +392,14 @@ public class ActionPGPEncryptFiles extends ActionBase 
implements Cloneable, IAct
       previousPgpFile.setWildcard(resolve(resultRow.getString(2, null)));
       previousPgpFile.setUserId(resultRow.getString(3, null));
       previousPgpFile.setDestinationFileFolder(resultRow.getString(4, null));
-      // The signing key is appended after the columns this action has always 
read, so a pipeline
-      // that still feeds five fields keeps working.
+      // The signing key and its passphrase are appended after the columns 
this action has always
+      // read, so a pipeline that still feeds five or six fields keeps working.
       if (resultRow.size() > 5) {
         previousPgpFile.setLocalUser(resultRow.getString(5, null));
       }
+      if (resultRow.size() > 6) {
+        previousPgpFile.setPassphrase(resultRow.getString(6, null));
+      }
 
       if (!Utils.isEmpty(previousPgpFile.getSourceFileFolder())
           && !Utils.isEmpty(previousPgpFile.getDestinationFileFolder())) {
@@ -413,6 +418,7 @@ public class ActionPGPEncryptFiles extends ActionBase 
implements Cloneable, IAct
             previousPgpFile.getSourceFileFolder(),
             previousPgpFile.getUserId(),
             previousPgpFile.getLocalUser(),
+            previousPgpFile.getPassphrase(),
             previousPgpFile.getDestinationFileFolder(),
             previousPgpFile.getWildcard(),
             parentWorkflow,
@@ -496,6 +502,7 @@ public class ActionPGPEncryptFiles extends ActionBase 
implements Cloneable, IAct
       String sourceFileFolderName,
       String userId,
       String localUser,
+      String passPhrase,
       String destinationFileFolderName,
       String wildcard,
       IWorkflowEngine<WorkflowMeta> parentWorkflow,
@@ -511,6 +518,7 @@ public class ActionPGPEncryptFiles extends ActionBase 
implements Cloneable, IAct
     String realSourceFileFolderName = resolve(sourceFileFolderName);
     String realUserId = resolve(userId);
     String realLocalUser = resolve(localUser);
+    String realPassPhrase = 
Encr.decryptPasswordOptionallyEncrypted(resolve(passPhrase));
     String realDestinationFileFolderName = resolve(destinationFileFolderName);
     String realWildcard = resolve(wildcard);
 
@@ -586,6 +594,7 @@ public class ActionPGPEncryptFiles extends ActionBase 
implements Cloneable, IAct
                       sourceFileFolder,
                       realUserId,
                       realLocalUser,
+                      realPassPhrase,
                       destinationFile,
                       moveToFolderFolder,
                       parentWorkflow,
@@ -626,6 +635,7 @@ public class ActionPGPEncryptFiles extends ActionBase 
implements Cloneable, IAct
                       sourceFileFolder,
                       realUserId,
                       realLocalUser,
+                      realPassPhrase,
                       destinationfile,
                       moveToFolderFolder,
                       parentWorkflow,
@@ -674,7 +684,7 @@ public class ActionPGPEncryptFiles extends ActionBase 
implements Cloneable, IAct
                               "" + nrErrors));
                       successConditionBrokenExit = true;
                     }
-                    return false;
+                    break;
                   }
                   // Fetch files in list one after one ...
                   currentFile = fileObjects[j];
@@ -684,6 +694,7 @@ public class ActionPGPEncryptFiles extends ActionBase 
implements Cloneable, IAct
                       sourceFileFolder,
                       realUserId,
                       realLocalUser,
+                      realPassPhrase,
                       realDestinationFileFolderName,
                       realWildcard,
                       parentWorkflow,
@@ -759,6 +770,7 @@ public class ActionPGPEncryptFiles extends ActionBase 
implements Cloneable, IAct
       FileObject sourceFileName,
       String userId,
       String localUser,
+      String passPhrase,
       FileObject destinationFileName,
       FileObject moveToFolderFolder,
       IWorkflowEngine<WorkflowMeta> parentWorkflow,
@@ -769,7 +781,7 @@ public class ActionPGPEncryptFiles extends ActionBase 
implements Cloneable, IAct
     try {
       if (!destinationFileName.exists()) {
 
-        doJob(actionType, sourceFileName, userId, localUser, 
destinationFileName);
+        doJob(actionType, sourceFileName, userId, localUser, passPhrase, 
destinationFileName);
         if (isDetailed()) {
           logDetailed(
               BaseMessages.getString(
@@ -779,10 +791,8 @@ public class ActionPGPEncryptFiles extends ActionBase 
implements Cloneable, IAct
                   destinationFileName.getName().toString()));
         }
 
-        // add filename to result filename
-        if (addResultFileNames
-            && !ifFileExists.equals("fail")
-            && !ifFileExists.equals(CONST_DO_NOTHING)) {
+        // The destination did not exist, so the option for an existing file 
does not apply.
+        if (addResultFileNames) {
           addFileToResultFilenames(destinationFileName.toString(), result, 
parentWorkflow);
         }
 
@@ -796,7 +806,7 @@ public class ActionPGPEncryptFiles extends ActionBase 
implements Cloneable, IAct
         }
         switch (ifFileExists) {
           case "overwrite_file" -> {
-            doJob(actionType, sourceFileName, userId, localUser, 
destinationFileName);
+            doJob(actionType, sourceFileName, userId, localUser, passPhrase, 
destinationFileName);
             if (isDetailed()) {
               logDetailed(
                   BaseMessages.getString(
@@ -807,7 +817,7 @@ public class ActionPGPEncryptFiles extends ActionBase 
implements Cloneable, IAct
 
             // add filename to result filename
             if (addResultFileNames
-                && !ifFileExists.equals("fail")
+                && !"fail".equals(ifFileExists)
                 && !ifFileExists.equals(CONST_DO_NOTHING)) {
               addFileToResultFilenames(destinationFileName.toString(), result, 
parentWorkflow);
             }
@@ -832,7 +842,7 @@ public class ActionPGPEncryptFiles extends ActionBase 
implements Cloneable, IAct
                 destinationFileName.getParent().toString() + 
Const.FILE_SEPARATOR + shortFilename;
             destinationFile = HopVfs.getFileObject(moveToFileNameFull, 
getVariables());
 
-            doJob(actionType, sourceFileName, userId, localUser, 
destinationFileName);
+            doJob(actionType, sourceFileName, userId, localUser, passPhrase, 
destinationFile);
             if (isDetailed()) {
               logDetailed(
                   toString(),
@@ -845,7 +855,7 @@ public class ActionPGPEncryptFiles extends ActionBase 
implements Cloneable, IAct
 
             // add filename to result filename
             if (addResultFileNames
-                && !ifFileExists.equals("fail")
+                && !"fail".equals(ifFileExists)
                 && !ifFileExists.equals(CONST_DO_NOTHING)) {
               addFileToResultFilenames(destinationFile.toString(), result, 
parentWorkflow);
             }
@@ -853,14 +863,15 @@ public class ActionPGPEncryptFiles extends ActionBase 
implements Cloneable, IAct
             updateSuccess();
           }
           case "delete_file" -> {
-            destinationFileName.delete();
+            sourceFileName.delete();
             if (isDetailed()) {
               logDetailed(
                   BaseMessages.getString(
                       PKG,
                       "ActionPGPEncryptFiles.Log.FileDeleted",
-                      destinationFileName.getName().toString()));
+                      sourceFileName.getName().toString()));
             }
+            updateSuccess();
           }
           case "move_file" -> {
             String shortFilename = shortFileName;
@@ -891,7 +902,7 @@ public class ActionPGPEncryptFiles extends ActionBase 
implements Cloneable, IAct
 
               // add filename to result filename
               if (addResultFileNames
-                  && !ifFileExists.equals("fail")
+                  && !"fail".equals(ifFileExists)
                   && !ifFileExists.equals(CONST_DO_NOTHING)) {
                 addFileToResultFilenames(destinationFile.toString(), result, 
parentWorkflow);
               }
@@ -910,7 +921,7 @@ public class ActionPGPEncryptFiles extends ActionBase 
implements Cloneable, IAct
 
                   // add filename to result filename
                   if (addResultFileNames
-                      && !ifFileExists.equals("fail")
+                      && !"fail".equals(ifFileExists)
                       && !ifFileExists.equals(CONST_DO_NOTHING)) {
                     addFileToResultFilenames(destinationFile.toString(), 
result, parentWorkflow);
                   }
@@ -939,7 +950,7 @@ public class ActionPGPEncryptFiles extends ActionBase 
implements Cloneable, IAct
 
                   // add filename to result filename
                   if (addResultFileNames
-                      && !ifFileExists.equals("fail")
+                      && !"fail".equals(ifFileExists)
                       && !ifFileExists.equals(CONST_DO_NOTHING)) {
                     addFileToResultFilenames(destinationFile.toString(), 
result, parentWorkflow);
                   }
@@ -955,7 +966,9 @@ public class ActionPGPEncryptFiles extends ActionBase 
implements Cloneable, IAct
           case "fail" ->
               // Update Errors
               updateErrors();
-          default -> {}
+          default -> {
+            // ignore code
+          }
         }
       }
     } catch (Exception e) {
@@ -985,6 +998,7 @@ public class ActionPGPEncryptFiles extends ActionBase 
implements Cloneable, IAct
       FileObject sourceFileFolder,
       String userId,
       String localUser,
+      String passPhrase,
       String realDestinationFileFolderName,
       String realWildcard,
       IWorkflowEngine<WorkflowMeta> parentWorkflow,
@@ -1043,6 +1057,7 @@ public class ActionPGPEncryptFiles extends ActionBase 
implements Cloneable, IAct
                     currentFile,
                     userId,
                     localUser,
+                    passPhrase,
                     filename,
                     moveToFolderFolder,
                     parentWorkflow,
@@ -1061,6 +1076,7 @@ public class ActionPGPEncryptFiles extends ActionBase 
implements Cloneable, IAct
                     currentFile,
                     userId,
                     localUser,
+                    passPhrase,
                     filename,
                     moveToFolderFolder,
                     parentWorkflow,
@@ -1292,15 +1308,17 @@ public class ActionPGPEncryptFiles extends ActionBase 
implements Cloneable, IAct
       FileObject sourceFile,
       String userID,
       String localUser,
+      String passPhrase,
       FileObject destinationFile)
       throws HopException {
 
     switch (actionType) {
       case SIGN:
-        gpg.signFile(sourceFile, localUser, destinationFile, isAsciiMode());
+        gpg.signFile(sourceFile, localUser, passPhrase, destinationFile, 
isAsciiMode());
         break;
       case SIGN_AND_ENCRYPT:
-        gpg.signAndEncryptFile(sourceFile, userID, localUser, destinationFile, 
isAsciiMode());
+        gpg.signAndEncryptFile(
+            sourceFile, userID, localUser, passPhrase, destinationFile, 
isAsciiMode());
         break;
       default:
         gpg.encryptFile(sourceFile, userID, destinationFile, isAsciiMode());
@@ -1386,6 +1404,13 @@ public class ActionPGPEncryptFiles extends ActionBase 
implements Cloneable, IAct
     @HopMetadataProperty(key = "local_user")
     public String localUser;
 
+    /**
+     * Passphrase of the signing key. Empty when the key has none. Stored 
encrypted and sent to
+     * GnuPG on standard input.
+     */
+    @HopMetadataProperty(key = "passphrase", password = true)
+    private String passphrase;
+
     @HopMetadataProperty(key = "destination_filefolder")
     public String destinationFileFolder;
 
@@ -1400,6 +1425,7 @@ public class ActionPGPEncryptFiles extends ActionBase 
implements Cloneable, IAct
       this.sourceFileFolder = f.sourceFileFolder;
       this.userId = f.userId;
       this.localUser = f.localUser;
+      this.passphrase = f.passphrase;
       this.destinationFileFolder = f.destinationFileFolder;
       this.wildcard = f.wildcard;
     }
diff --git 
a/plugins/actions/pgpfiles/src/main/java/org/apache/hop/workflow/actions/pgpencryptfiles/ActionPGPEncryptFilesDialog.java
 
b/plugins/actions/pgpfiles/src/main/java/org/apache/hop/workflow/actions/pgpencryptfiles/ActionPGPEncryptFilesDialog.java
index 33efe7cc1d..2c3d8e3d90 100644
--- 
a/plugins/actions/pgpfiles/src/main/java/org/apache/hop/workflow/actions/pgpencryptfiles/ActionPGPEncryptFilesDialog.java
+++ 
b/plugins/actions/pgpfiles/src/main/java/org/apache/hop/workflow/actions/pgpencryptfiles/ActionPGPEncryptFilesDialog.java
@@ -519,6 +519,10 @@ public class ActionPGPEncryptFilesDialog extends 
ActionDialog {
               BaseMessages.getString(PKG, 
"ActionPGPEncryptFiles.Fields.LocalUser.Label"),
               ColumnInfo.COLUMN_TYPE_TEXT,
               false),
+          new ColumnInfo(
+              BaseMessages.getString(PKG, 
"ActionPGPEncryptFiles.Fields.Passphrase.Label"),
+              ColumnInfo.COLUMN_TYPE_TEXT,
+              false),
           new ColumnInfo(
               BaseMessages.getString(
                   PKG, 
"ActionPGPEncryptFiles.Fields.DestinationFileFolder.Label"),
@@ -535,6 +539,9 @@ public class ActionPGPEncryptFilesDialog extends 
ActionDialog {
     columnInfos[4].setToolTip(
         BaseMessages.getString(PKG, 
"ActionPGPEncryptFiles.Fields.LocalUser.Tooltip"));
     columnInfos[5].setToolTip(
+        BaseMessages.getString(PKG, 
"ActionPGPEncryptFiles.Fields.Passphrase.Tooltip"));
+    columnInfos[5].setPasswordField(true);
+    columnInfos[6].setToolTip(
         BaseMessages.getString(PKG, 
"ActionPGPEncryptFiles.Fields.DestinationFileFolder.Tooltip"));
 
     columnInfos[0].setUsingVariables(true);
@@ -543,6 +550,7 @@ public class ActionPGPEncryptFilesDialog extends 
ActionDialog {
     columnInfos[3].setUsingVariables(true);
     columnInfos[4].setUsingVariables(true);
     columnInfos[5].setUsingVariables(true);
+    columnInfos[6].setUsingVariables(true);
 
     wFields =
         new TableView(
@@ -574,6 +582,7 @@ public class ActionPGPEncryptFilesDialog extends 
ActionDialog {
                 wWildcard.getText(),
                 null,
                 null,
+                null,
                 wDestinationFileFolder.getText());
             wSourceFileFolder.setText("");
             wDestinationFileFolder.setText("");
@@ -606,7 +615,7 @@ public class ActionPGPEncryptFilesDialog extends 
ActionDialog {
           if (idx >= 0) {
             String[] string = wFields.getItem(idx);
             wSourceFileFolder.setText(string[1]);
-            wDestinationFileFolder.setText(string[5]);
+            wDestinationFileFolder.setText(string[6]);
             wWildcard.setText(string[2]);
             wFields.remove(idx);
           }
@@ -1557,7 +1566,8 @@ public class ActionPGPEncryptFilesDialog extends 
ActionDialog {
       ti.setText(3, Const.NVL(pgpFile.getWildcard(), ""));
       ti.setText(4, Const.NVL(pgpFile.getUserId(), ""));
       ti.setText(5, Const.NVL(pgpFile.getLocalUser(), ""));
-      ti.setText(6, Const.NVL(pgpFile.getDestinationFileFolder(), ""));
+      ti.setText(6, Const.NVL(pgpFile.getPassphrase(), ""));
+      ti.setText(7, Const.NVL(pgpFile.getDestinationFileFolder(), ""));
     }
     wFields.optimizeTableView();
   }
@@ -1652,7 +1662,8 @@ public class ActionPGPEncryptFilesDialog extends 
ActionDialog {
       pgpFile.setWildcard(item.getText(3));
       pgpFile.setUserId(item.getText(4));
       pgpFile.setLocalUser(item.getText(5));
-      pgpFile.setDestinationFileFolder(item.getText(6));
+      pgpFile.setPassphrase(item.getText(6));
+      pgpFile.setDestinationFileFolder(item.getText(7));
     }
     dispose();
   }
diff --git 
a/plugins/actions/pgpfiles/src/main/java/org/apache/hop/workflow/actions/pgpencryptfiles/GPG.java
 
b/plugins/actions/pgpfiles/src/main/java/org/apache/hop/workflow/actions/pgpencryptfiles/GPG.java
index 9e8263759c..d6c06e6c5c 100644
--- 
a/plugins/actions/pgpfiles/src/main/java/org/apache/hop/workflow/actions/pgpencryptfiles/GPG.java
+++ 
b/plugins/actions/pgpfiles/src/main/java/org/apache/hop/workflow/actions/pgpencryptfiles/GPG.java
@@ -126,7 +126,8 @@ public class GPG {
       file = HopVfs.getFileObject(getGpgExeFile(), variables);
 
       if (!file.exists()) {
-        throw new HopException(BaseMessages.getString(PKG, 
"GPG.GPGFilenameNotFound"));
+        throw new HopException(
+            BaseMessages.getString(PKG, "GPG.GPGFilenameNotFound", 
getGpgExeFile()));
       }
       // The file exists
       if (!file.getType().equals(FileType.FILE)) {
@@ -439,8 +440,30 @@ public class GPG {
   public void signAndEncryptFile(
       FileObject file, String userID, String localUser, FileObject 
cryptedFile, boolean asciiMode)
       throws HopException {
+    signAndEncryptFile(file, userID, localUser, null, cryptedFile, asciiMode);
+  }
+
+  /**
+   * Sign and encrypt a file.
+   *
+   * @param passPhrase passphrase of the signing key, or empty when that key 
has none. It is written
+   *     to GnuPG's standard input, never placed on the command line.
+   */
+  public void signAndEncryptFile(
+      FileObject file,
+      String userID,
+      String localUser,
+      String passPhrase,
+      FileObject cryptedFile,
+      boolean asciiMode)
+      throws HopException {
     signAndEncryptFile(
-        HopVfs.getFilename(file), userID, localUser, 
HopVfs.getFilename(cryptedFile), asciiMode);
+        HopVfs.getFilename(file),
+        userID,
+        localUser,
+        passPhrase,
+        HopVfs.getFilename(cryptedFile),
+        asciiMode);
   }
 
   /**
@@ -471,6 +494,23 @@ public class GPG {
   public void signAndEncryptFile(
       String filename, String userID, String localUser, String 
cryptedFilename, boolean asciiMode)
       throws HopException {
+    signAndEncryptFile(filename, userID, localUser, null, cryptedFilename, 
asciiMode);
+  }
+
+  /**
+   * Sign and encrypt a file.
+   *
+   * @param passPhrase passphrase of the signing key, or empty when that key 
has none. It is written
+   *     to GnuPG's standard input, never placed on the command line.
+   */
+  public void signAndEncryptFile(
+      String filename,
+      String userID,
+      String localUser,
+      String passPhrase,
+      String cryptedFilename,
+      boolean asciiMode)
+      throws HopException {
 
     try {
       List<String> args = new ArrayList<>(BATCH_YES);
@@ -479,6 +519,10 @@ public class GPG {
       }
       addRecipient(args, userID);
       addLocalUser(args, localUser);
+      boolean withPassPhrase = !Utils.isEmpty(passPhrase);
+      if (withPassPhrase) {
+        addPassPhraseFromStdin(args);
+      }
       args.add("--output");
       args.add(cryptedFilename);
       args.add("--encrypt");
@@ -486,7 +530,7 @@ public class GPG {
       args.add(END_OF_OPTIONS);
       args.add(filename);
 
-      execGnuPG(args, null, true);
+      execGnuPG(args, withPassPhrase ? passPhrase : null, true);
     } catch (Exception e) {
       throw new HopException(e);
     }
@@ -508,19 +552,39 @@ public class GPG {
    */
   public void signFile(String filename, String localUser, String 
signedFilename, boolean asciiMode)
       throws HopException {
+    signFile(filename, localUser, null, signedFilename, asciiMode);
+  }
+
+  /**
+   * Sign a file.
+   *
+   * @param passPhrase passphrase of the signing key, or empty when that key 
has none. It is written
+   *     to GnuPG's standard input, never placed on the command line.
+   */
+  public void signFile(
+      String filename,
+      String localUser,
+      String passPhrase,
+      String signedFilename,
+      boolean asciiMode)
+      throws HopException {
     try {
       List<String> args = new ArrayList<>(BATCH_YES);
       if (asciiMode) {
         args.add("-a");
       }
       addLocalUser(args, localUser);
+      boolean withPassPhrase = !Utils.isEmpty(passPhrase);
+      if (withPassPhrase) {
+        addPassPhraseFromStdin(args);
+      }
       args.add("--output");
       args.add(signedFilename);
       args.add(asciiMode ? "--clearsign" : "--sign");
       args.add(END_OF_OPTIONS);
       args.add(filename);
 
-      execGnuPG(args, null, true);
+      execGnuPG(args, withPassPhrase ? passPhrase : null, true);
 
     } catch (Exception e) {
       throw new HopException(e);
@@ -539,8 +603,29 @@ public class GPG {
    */
   public void signFile(FileObject file, String localUser, FileObject 
signedFile, boolean asciiMode)
       throws HopException {
+    signFile(file, localUser, null, signedFile, asciiMode);
+  }
+
+  /**
+   * Sign a file.
+   *
+   * @param passPhrase passphrase of the signing key, or empty when that key 
has none. It is written
+   *     to GnuPG's standard input, never placed on the command line.
+   */
+  public void signFile(
+      FileObject file,
+      String localUser,
+      String passPhrase,
+      FileObject signedFile,
+      boolean asciiMode)
+      throws HopException {
     try {
-      signFile(HopVfs.getFilename(file), localUser, 
HopVfs.getFilename(signedFile), asciiMode);
+      signFile(
+          HopVfs.getFilename(file),
+          localUser,
+          passPhrase,
+          HopVfs.getFilename(signedFile),
+          asciiMode);
 
     } catch (Exception e) {
       throw new HopException(e);
diff --git 
a/plugins/actions/pgpfiles/src/main/resources/org/apache/hop/workflow/actions/pgpdecryptfiles/messages/messages_en_US.properties
 
b/plugins/actions/pgpfiles/src/main/resources/org/apache/hop/workflow/actions/pgpdecryptfiles/messages/messages_en_US.properties
index 51278ce0b2..ffed330829 100644
--- 
a/plugins/actions/pgpfiles/src/main/resources/org/apache/hop/workflow/actions/pgpdecryptfiles/messages/messages_en_US.properties
+++ 
b/plugins/actions/pgpfiles/src/main/resources/org/apache/hop/workflow/actions/pgpdecryptfiles/messages/messages_en_US.properties
@@ -50,6 +50,7 @@ ActionPGPDecryptFiles.Do_Nothing_IfFileExists.Label=Do nothing
 ActionPGPDecryptFiles.Do_Nothing_IfMovedFileExists.Label=Do nothing
 ActionPGPDecryptFiles.DoNotKeepFolderStructure.Label=Do not keep folder 
structure
 ActionPGPDecryptFiles.DoNotKeepFolderStructure.Tooltip=Check this option if 
you want to decrypt and create files in\n destination file without keeping 
folders structure.
+ActionPGPDecryptFiles.Error=Error decrypting files! {0}
 ActionPGPDecryptFiles.Error.AddingToFilenameResult=Error adding filename [{0}] 
to result filenames. Exception : {1}
 ActionPGPDecryptFiles.Error.DestinationFolderNotFound=Destination folder does 
not exist!
 ActionPGPDecryptFiles.Error.Exception.MoveProcess=Can not move file/folder 
[{0}] to [{1}]. Exception : [{2}]
diff --git 
a/plugins/actions/pgpfiles/src/main/resources/org/apache/hop/workflow/actions/pgpencryptfiles/messages/messages_en_US.properties
 
b/plugins/actions/pgpfiles/src/main/resources/org/apache/hop/workflow/actions/pgpencryptfiles/messages/messages_en_US.properties
index 09f2bf8e81..748fae59ec 100644
--- 
a/plugins/actions/pgpfiles/src/main/resources/org/apache/hop/workflow/actions/pgpencryptfiles/messages/messages_en_US.properties
+++ 
b/plugins/actions/pgpfiles/src/main/resources/org/apache/hop/workflow/actions/pgpencryptfiles/messages/messages_en_US.properties
@@ -72,6 +72,8 @@ 
ActionPGPEncryptFiles.Fields.DestinationFileFolder.Tooltip=Enter here the destin
 ActionPGPEncryptFiles.Fields.Label=Files/Folders: 
 ActionPGPEncryptFiles.Fields.LocalUser.Label=Signing key
 ActionPGPEncryptFiles.Fields.LocalUser.Tooltip=User ID of the key to sign with 
(gpg ''-u'').\n Leave empty to let GnuPG use the default key from its 
configuration.\n Ignored when the action only encrypts.
+ActionPGPEncryptFiles.Fields.Passphrase.Label=Passphrase
+ActionPGPEncryptFiles.Fields.Passphrase.Tooltip=Passphrase of the signing 
key.\n Sent to GnuPG on standard input, never on the command line.\n Leave 
empty when the key has no passphrase.\n Ignored when the action only encrypts.
 ActionPGPEncryptFiles.Fields.SourceFileFolder.Label=File/Folder source
 ActionPGPEncryptFiles.Fields.SourceFileFolder.Tooltip=Enter here the file or 
folder to move\n If it's a folder, Apache Hop will fetch only if ''Include 
subfolders'' is checked!
 ActionPGPEncryptFiles.Fields.UserID.Label=User ID
@@ -148,7 +150,7 @@ 
ActionPGPEncryptFiles.UniqueName_IfMovedFileExists.Label=Unique name
 ActionPGPEncryptFiles.Wildcard.Label=Wildcard
 ActionPGPEncryptFiles.Wildcard.Tooltip=Specify here the wildcard to match.\n 
Only files that match the wildcard will be moved.
 GPG.DeletingTempFile=Deleting GPG temporary file [{0}] ...
-GPG.ErrorCheckingGPGFile=Error checking PGP file
+GPG.ErrorCheckingGPGFile=Error checking PGP file [{0}]
 GPG.ErrorCreatingTempFile=Cannot create GPG temporary file!
 GPG.ErrorWritingTempFile=Cannot write GPG temporary file! 
 GPG.Exception.ExistStatus=Error running command: {0}
diff --git 
a/plugins/actions/pgpfiles/src/test/java/org/apache/hop/workflow/actions/pgpencryptfiles/ActionPGPEncryptFilesDialogTest.java
 
b/plugins/actions/pgpfiles/src/test/java/org/apache/hop/workflow/actions/pgpencryptfiles/ActionPGPEncryptFilesDialogTest.java
index 77c0baa5c8..33f55b2110 100644
--- 
a/plugins/actions/pgpfiles/src/test/java/org/apache/hop/workflow/actions/pgpencryptfiles/ActionPGPEncryptFilesDialogTest.java
+++ 
b/plugins/actions/pgpfiles/src/test/java/org/apache/hop/workflow/actions/pgpencryptfiles/ActionPGPEncryptFilesDialogTest.java
@@ -104,6 +104,7 @@ class ActionPGPEncryptFilesDialogTest extends 
SwtBotTestBase {
           typeInto(grid, 0, headers.indexOf(label("Wildcard")), 
"typed-under-wildcard");
           typeInto(grid, 0, headers.indexOf(label("UserID")), 
"typed-under-user-id");
           typeInto(grid, 0, headers.indexOf(label("LocalUser")), 
"typed-under-local-user");
+          typeInto(grid, 0, headers.indexOf(label("Passphrase")), 
"typed-under-passphrase");
           typeInto(grid, 0, headers.indexOf(label("DestinationFileFolder")), 
"typed-under-dest");
         });
 
@@ -112,6 +113,7 @@ class ActionPGPEncryptFilesDialogTest extends 
SwtBotTestBase {
     assertEquals("typed-under-wildcard", row.getWildcard(), label("Wildcard"));
     assertEquals("typed-under-user-id", row.getUserId(), label("UserID"));
     assertEquals("typed-under-local-user", row.getLocalUser(), 
label("LocalUser"));
+    assertEquals("typed-under-passphrase", row.getPassphrase(), 
label("Passphrase"));
     assertEquals(
         "typed-under-dest", row.getDestinationFileFolder(), 
label("DestinationFileFolder"));
   }
diff --git 
a/plugins/actions/pgpfiles/src/test/java/org/apache/hop/workflow/actions/pgpencryptfiles/ActionPGPEncryptFilesTest.java
 
b/plugins/actions/pgpfiles/src/test/java/org/apache/hop/workflow/actions/pgpencryptfiles/ActionPGPEncryptFilesTest.java
index dc055fc07d..f0386925d3 100644
--- 
a/plugins/actions/pgpfiles/src/test/java/org/apache/hop/workflow/actions/pgpencryptfiles/ActionPGPEncryptFilesTest.java
+++ 
b/plugins/actions/pgpfiles/src/test/java/org/apache/hop/workflow/actions/pgpencryptfiles/ActionPGPEncryptFilesTest.java
@@ -19,6 +19,7 @@
 package org.apache.hop.workflow.actions.pgpencryptfiles;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
@@ -27,9 +28,15 @@ import 
org.apache.hop.core.encryption.HopTwoWayPasswordEncoder;
 import org.apache.hop.core.encryption.TwoWayPasswordEncoderPlugin;
 import org.apache.hop.core.encryption.TwoWayPasswordEncoderPluginType;
 import org.apache.hop.core.plugins.PluginRegistry;
+import org.apache.hop.core.xml.XmlHandler;
+import org.apache.hop.metadata.serializer.memory.MemoryMetadataProvider;
+import org.apache.hop.metadata.serializer.xml.XmlMetadataUtil;
+import org.apache.hop.workflow.action.ActionMeta;
 import org.apache.hop.workflow.action.ActionSerializationTestUtil;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
 
 class ActionPGPEncryptFilesTest {
   @BeforeEach
@@ -77,6 +84,7 @@ class ActionPGPEncryptFilesTest {
     assertEquals("user1", f.getUserId());
     // Written before the signing key had a field of its own, so it has none.
     assertNull(f.getLocalUser());
+    assertNull(f.getPassphrase());
     assertEquals("target1", f.getDestinationFileFolder());
     assertEquals("wildcard1", f.getWildcard());
     f = action.getPgpFiles().get(1);
@@ -91,7 +99,31 @@ class ActionPGPEncryptFilesTest {
     assertEquals("folder3", f.getSourceFileFolder());
     assertEquals("user3", f.getUserId());
     assertEquals("signer3", f.getLocalUser());
+    assertNull(f.getPassphrase());
     assertEquals("target3", f.getDestinationFileFolder());
     assertEquals("wildcard3", f.getWildcard());
   }
+
+  /** A passphrase is a secret: the workflow XML stores it encrypted, and 
loading gives it back. */
+  @Test
+  void passphraseIsStoredEncryptedAndLoadedAsPlaintext() throws Exception {
+    ActionPGPEncryptFiles action = new ActionPGPEncryptFiles("pgp");
+    ActionPGPEncryptFiles.PgpFile file = new ActionPGPEncryptFiles.PgpFile();
+    file.setActionType(ActionPGPEncryptFiles.ActionType.SIGN);
+    file.setSourceFileFolder("plain.txt");
+    file.setPassphrase("secret");
+    file.setDestinationFileFolder("plain.txt.asc");
+    action.getPgpFiles().add(file);
+
+    String xml = ActionSerializationTestUtil.getXml(action);
+    assertFalse(xml.contains(">secret<"), xml);
+    assertTrue(xml.contains("Encrypted "), xml);
+
+    Document document = XmlHandler.loadXmlString(xml);
+    Node node = XmlHandler.getSubNode(document, ActionMeta.XML_TAG);
+    ActionPGPEncryptFiles loaded =
+        XmlMetadataUtil.deSerializeFromXml(
+            node, ActionPGPEncryptFiles.class, new MemoryMetadataProvider());
+    assertEquals("secret", loaded.getPgpFiles().getFirst().getPassphrase());
+  }
 }
diff --git 
a/plugins/actions/pgpfiles/src/test/java/org/apache/hop/workflow/actions/pgpencryptfiles/ActionPGPFilesBehaviorTest.java
 
b/plugins/actions/pgpfiles/src/test/java/org/apache/hop/workflow/actions/pgpencryptfiles/ActionPGPFilesBehaviorTest.java
new file mode 100644
index 0000000000..6f4f7f91e7
--- /dev/null
+++ 
b/plugins/actions/pgpfiles/src/test/java/org/apache/hop/workflow/actions/pgpencryptfiles/ActionPGPFilesBehaviorTest.java
@@ -0,0 +1,207 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hop.workflow.actions.pgpencryptfiles;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Comparator;
+import org.apache.hop.core.Result;
+import org.apache.hop.core.encryption.Encr;
+import org.apache.hop.core.encryption.HopTwoWayPasswordEncoder;
+import org.apache.hop.core.encryption.TwoWayPasswordEncoderPlugin;
+import org.apache.hop.core.encryption.TwoWayPasswordEncoderPluginType;
+import org.apache.hop.core.logging.HopLogStore;
+import org.apache.hop.core.plugins.PluginRegistry;
+import org.apache.hop.workflow.WorkflowMeta;
+import org.apache.hop.workflow.action.ActionBase;
+import org.apache.hop.workflow.actions.pgpdecryptfiles.ActionPGPDecryptFiles;
+import org.apache.hop.workflow.engine.IWorkflowEngine;
+import org.apache.hop.workflow.engines.local.LocalWorkflowEngine;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * The conflict options and a missing GnuPG program, exercised without 
invoking GnuPG. See <a
+ * href="https://github.com/apache/hop/issues/9207";>issue-9207</a>.
+ */
+class ActionPGPFilesBehaviorTest {
+
+  private Path sandbox;
+
+  @BeforeAll
+  static void initRuntime() throws Exception {
+    HopLogStore.init();
+    PluginRegistry.getInstance()
+        .registerPluginClass(
+            HopTwoWayPasswordEncoder.class.getName(),
+            TwoWayPasswordEncoderPluginType.class,
+            TwoWayPasswordEncoderPlugin.class);
+    Encr.init("Hop");
+  }
+
+  @BeforeEach
+  void createSandbox() throws Exception {
+    sandbox = Files.createTempDirectory("hop-pgp-behavior");
+  }
+
+  @AfterEach
+  void removeSandbox() throws Exception {
+    if (sandbox == null || !Files.exists(sandbox)) {
+      return;
+    }
+    try (var paths = Files.walk(sandbox)) {
+      paths.sorted(Comparator.reverseOrder()).forEach(path -> 
path.toFile().delete());
+    }
+  }
+
+  @Test
+  void missingGpgMakesEncryptFalseWithoutThrowing() {
+    ActionPGPEncryptFiles action = 
encryptAction(sandbox.resolve("missing-gpg").toString());
+    Result result = assertDoesNotThrow(() -> action.execute(new Result(), 0));
+
+    assert result != null;
+    assertFalse(result.isResult());
+    assertEquals(1, result.getNrErrors());
+  }
+
+  @Test
+  void missingGpgMakesDecryptFalseWithoutThrowing() {
+    ActionPGPDecryptFiles action = 
decryptAction(sandbox.resolve("missing-gpg").toString());
+    Result result = assertDoesNotThrow(() -> action.execute(new Result(), 0));
+
+    assert result != null;
+    assertFalse(result.isResult());
+    assertEquals(1, result.getNrErrors());
+  }
+
+  @Test
+  void oneFolderFailureIsNotCountedTwiceForEncrypt() throws Exception {
+    Path source = sandbox.resolve("in");
+    Path destination = sandbox.resolve("out");
+    Files.createDirectories(source);
+    Files.createDirectories(destination);
+    Files.writeString(source.resolve("a.txt"), "A");
+    Files.writeString(source.resolve("b.txt"), "B");
+    Files.writeString(destination.resolve("a.txt"), "KEEP-A");
+    Files.writeString(destination.resolve("b.txt"), "KEEP-B");
+
+    ActionPGPEncryptFiles action = 
encryptAction(sandbox.resolve("gpg-unused").toString());
+    Files.writeString(sandbox.resolve("gpg-unused"), "not gpg");
+    action.setIfFileExists("fail");
+    action.setSuccessCondition(ActionPGPEncryptFiles.SUCCESS_IF_ERRORS_LESS);
+    action.setNrErrorsLessThan("1");
+    action.getPgpFiles().add(encryptFile(source, destination));
+
+    Result result = action.execute(new Result(), 0);
+
+    assertTrue(result.isResult(), "one error still satisfies nrErrors <= 1");
+    assertEquals(1, result.getNrErrors());
+    assertEquals("KEEP-A", Files.readString(destination.resolve("a.txt")));
+    assertEquals("KEEP-B", Files.readString(destination.resolve("b.txt")));
+  }
+
+  @Test
+  void oneFolderFailureIsNotCountedTwiceForDecrypt() throws Exception {
+    Path source = sandbox.resolve("in");
+    Path destination = sandbox.resolve("out");
+    Files.createDirectories(source);
+    Files.createDirectories(destination);
+    Files.writeString(source.resolve("a.txt"), "A");
+    Files.writeString(source.resolve("b.txt"), "B");
+    Files.writeString(destination.resolve("a.txt"), "KEEP-A");
+    Files.writeString(destination.resolve("b.txt"), "KEEP-B");
+
+    ActionPGPDecryptFiles action = 
decryptAction(sandbox.resolve("gpg-unused").toString());
+    Files.writeString(sandbox.resolve("gpg-unused"), "not gpg");
+    action.setIfFileExists(ActionPGPDecryptFiles.CONST_FAIL);
+    action.setSuccessCondition(ActionPGPDecryptFiles.SUCCESS_IF_ERRORS_LESS);
+    action.setNrErrorsLessThan("1");
+    ActionPGPDecryptFiles.FileToDecrypt file = new 
ActionPGPDecryptFiles.FileToDecrypt();
+    file.setSourceFileFolder(source.toString());
+    file.setDestinationFileFolder(destination.toString());
+    action.getFilesToDecrypt().add(file);
+
+    Result result = action.execute(new Result(), 0);
+
+    assertTrue(result.isResult(), "one error still satisfies nrErrors <= 1");
+    assertEquals(1, result.getNrErrors());
+  }
+
+  @Test
+  void doNothingLeavesAnExistingDestinationAndAddsNoResultFile() throws 
Exception {
+    Path source = sandbox.resolve("plain.txt");
+    Path destination = sandbox.resolve("out").resolve("plain.txt");
+    Files.writeString(source, "PLAIN");
+    Files.createDirectories(destination.getParent());
+    Files.writeString(destination, "OLD");
+    Path gpg = sandbox.resolve("gpg-unused");
+    Files.writeString(gpg, "not gpg");
+
+    ActionPGPEncryptFiles action = encryptAction(gpg.toString());
+    action.setAddResultFileNames(true);
+    action.setDestinationIsAFile(true);
+    action.setIfFileExists("do_nothing");
+    action.getPgpFiles().add(encryptFile(source, destination));
+
+    Result result = action.execute(new Result(), 0);
+
+    assertTrue(result.isResult());
+    assertEquals(0, result.getNrErrors());
+    assertEquals(0, result.getNrLinesWritten());
+    assertTrue(result.getResultFiles().isEmpty());
+    assertEquals("OLD", Files.readString(destination));
+    assertEquals("PLAIN", Files.readString(source));
+  }
+
+  private ActionPGPEncryptFiles encryptAction(String gpgLocation) {
+    ActionPGPEncryptFiles action = new ActionPGPEncryptFiles("encrypt");
+    action.setGpgLocation(gpgLocation);
+    attach(action);
+    return action;
+  }
+
+  private ActionPGPDecryptFiles decryptAction(String gpgLocation) {
+    ActionPGPDecryptFiles action = new ActionPGPDecryptFiles("decrypt");
+    action.setGpgLocation(gpgLocation);
+    attach(action);
+    return action;
+  }
+
+  private static ActionPGPEncryptFiles.PgpFile encryptFile(Path source, Path 
destination) {
+    ActionPGPEncryptFiles.PgpFile file = new ActionPGPEncryptFiles.PgpFile();
+    file.setActionType(ActionPGPEncryptFiles.ActionType.ENCRYPT);
+    file.setUserId("[email protected]");
+    file.setSourceFileFolder(source.toString());
+    file.setDestinationFileFolder(destination.toString());
+    return file;
+  }
+
+  private static void attach(ActionBase action) {
+    WorkflowMeta meta = new WorkflowMeta();
+    meta.setName("pgp-test");
+    IWorkflowEngine<WorkflowMeta> workflow = new LocalWorkflowEngine(meta);
+    action.setParentWorkflow(workflow);
+  }
+}
diff --git 
a/plugins/actions/pgpfiles/src/test/java/org/apache/hop/workflow/actions/pgpencryptfiles/ActionPGPFilesConflictTest.java
 
b/plugins/actions/pgpfiles/src/test/java/org/apache/hop/workflow/actions/pgpencryptfiles/ActionPGPFilesConflictTest.java
new file mode 100644
index 0000000000..bb4e311369
--- /dev/null
+++ 
b/plugins/actions/pgpfiles/src/test/java/org/apache/hop/workflow/actions/pgpencryptfiles/ActionPGPFilesConflictTest.java
@@ -0,0 +1,343 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hop.workflow.actions.pgpencryptfiles;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Comparator;
+import java.util.List;
+import java.util.stream.Stream;
+import org.apache.hop.core.Result;
+import org.apache.hop.core.RowMetaAndData;
+import org.apache.hop.core.encryption.Encr;
+import org.apache.hop.core.encryption.HopTwoWayPasswordEncoder;
+import org.apache.hop.core.encryption.TwoWayPasswordEncoderPlugin;
+import org.apache.hop.core.encryption.TwoWayPasswordEncoderPluginType;
+import org.apache.hop.core.logging.HopLogStore;
+import org.apache.hop.core.plugins.PluginRegistry;
+import org.apache.hop.core.row.RowMeta;
+import org.apache.hop.core.row.value.ValueMetaString;
+import org.apache.hop.workflow.WorkflowMeta;
+import org.apache.hop.workflow.action.ActionBase;
+import org.apache.hop.workflow.actions.pgpdecryptfiles.ActionPGPDecryptFiles;
+import org.apache.hop.workflow.engine.IWorkflowEngine;
+import org.apache.hop.workflow.engines.local.LocalWorkflowEngine;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Conflict options that have to run GnuPG, with a stub that copies the source 
onto {@code
+ * --output}. See <a 
href="https://github.com/apache/hop/issues/9207";>issue-9207</a>.
+ */
+class ActionPGPFilesConflictTest {
+
+  private static Path root;
+  private static Path stub;
+
+  @BeforeAll
+  static void initRuntime() throws Exception {
+    HopLogStore.init();
+    PluginRegistry.getInstance()
+        .registerPluginClass(
+            HopTwoWayPasswordEncoder.class.getName(),
+            TwoWayPasswordEncoderPluginType.class,
+            TwoWayPasswordEncoderPlugin.class);
+    Encr.init("Hop");
+    root = Files.createTempDirectory("hop-pgp-conflict");
+    stub = GpgCopyStub.install(root.resolve("stub"));
+  }
+
+  @AfterAll
+  static void removeRoot() throws Exception {
+    if (root == null || !Files.exists(root)) {
+      return;
+    }
+    try (var paths = Files.walk(root)) {
+      paths.sorted(Comparator.reverseOrder()).forEach(path -> 
path.toFile().delete());
+    }
+  }
+
+  @Test
+  void uniqueNameKeepsTheExistingFileAndWritesANewOne() throws Exception {
+    Path source = file("unique/plain.txt", "PLAIN");
+    Path destination = file("unique/out/plain.txt", "OLD");
+    ActionPGPEncryptFiles action = encrypt("unique_name", source, destination);
+    Result result = action.execute(new Result(), 0);
+
+    assertTrue(result.isResult());
+    assertEquals(1, result.getNrLinesWritten());
+    assertEquals("OLD", Files.readString(destination));
+    Path created;
+    try (Stream<Path> listed = Files.list(destination.getParent())) {
+      created =
+          listed
+              .filter(path -> 
!path.getFileName().toString().equals("plain.txt"))
+              .findFirst()
+              .orElseThrow();
+    }
+    assertEquals("PLAIN", Files.readString(created));
+    assertEquals(1, result.getResultFiles().size());
+    assertTrue(
+        result
+            .getResultFiles()
+            .keySet()
+            .iterator()
+            .next()
+            .contains(created.getFileName().toString()));
+  }
+
+  @Test
+  void deleteSourceRemovesTheSourceAndLeavesTheDestination() throws Exception {
+    Path source = file("delete/plain.txt", "PLAIN");
+    Path destination = file("delete/out/plain.txt", "OLD");
+    ActionPGPEncryptFiles action = encrypt("delete_file", source, destination);
+    Result result = action.execute(new Result(), 0);
+
+    assertTrue(result.isResult());
+    assertEquals(1, result.getNrLinesWritten());
+    assertEquals(0, result.getNrErrors());
+    assertFalse(Files.exists(source));
+    assertEquals("OLD", Files.readString(destination));
+    assertEquals(0, result.getResultFiles().size());
+  }
+
+  @Test
+  void moveSourceLeavesTheDestinationAndMovesTheSource() throws Exception {
+    Path source = file("move/plain.txt", "PLAIN");
+    Path destination = file("move/out/plain.txt", "OLD");
+    Path moved = root.resolve("move/moved");
+    Files.createDirectories(moved);
+    ActionPGPEncryptFiles action = encrypt("move_file", source, destination);
+    action.setDestinationFolder(moved.toString());
+    action.setCreateMoveToFolder(true);
+    Result result = action.execute(new Result(), 0);
+
+    assertTrue(result.isResult());
+    assertEquals(0, result.getNrLinesWritten());
+    assertEquals(0, result.getNrErrors());
+    assertFalse(Files.exists(source));
+    assertEquals("OLD", Files.readString(destination));
+    assertEquals("PLAIN", Files.readString(moved.resolve("plain.txt")));
+    assertEquals(1, result.getResultFiles().size());
+    String registered = result.getResultFiles().keySet().iterator().next();
+    assertTrue(registered.contains("moved"), registered);
+    assertFalse(registered.contains("out"), registered);
+  }
+
+  @Test
+  void moveFailsWhenTheMovedFileExistsAndCountsOnlyAnError() throws Exception {
+    Path source = file("move-fail/plain.txt", "PLAIN");
+    Path destination = file("move-fail/out/plain.txt", "OLD");
+    Path moved = root.resolve("move-fail/moved");
+    Files.createDirectories(moved);
+    Files.writeString(moved.resolve("plain.txt"), "ALREADY");
+    ActionPGPEncryptFiles action = encrypt("move_file", source, destination);
+    action.setDestinationFolder(moved.toString());
+    action.setCreateMoveToFolder(true);
+    action.setIfMovedFileExists("fail");
+    Result result = action.execute(new Result(), 0);
+
+    assertFalse(result.isResult());
+    assertEquals(1, result.getNrErrors());
+    assertEquals(0, result.getNrLinesWritten());
+    assertEquals("PLAIN", Files.readString(source));
+    assertEquals("OLD", Files.readString(destination));
+    assertEquals("ALREADY", Files.readString(moved.resolve("plain.txt")));
+    assertEquals(0, result.getResultFiles().size());
+  }
+
+  @Test
+  void doNothingOnANewFileAddsThatFileToTheResult() throws Exception {
+    Path source = file("nothing/plain.txt", "PLAIN");
+    Path destination = root.resolve("nothing/out/plain.txt");
+    Files.createDirectories(destination.getParent());
+    ActionPGPEncryptFiles action = encrypt("do_nothing", source, destination);
+    Result result = action.execute(new Result(), 0);
+
+    assertTrue(result.isResult());
+    assertEquals(1, result.getNrLinesWritten());
+    assertEquals("PLAIN", Files.readString(destination));
+    assertEquals(1, result.getResultFiles().size());
+  }
+
+  @Test
+  void decryptDeleteSourceRemovesTheSourceAndLeavesTheDestination() throws 
Exception {
+    Path source = file("d-delete/sealed.gpg", "SEALED");
+    Path destination = file("d-delete/out/sealed.gpg", "OLD");
+    Result result = decrypt(source, destination);
+
+    assertTrue(result.isResult());
+    assertEquals(1, result.getNrLinesWritten());
+    assertEquals(0, result.getNrErrors());
+    assertFalse(Files.exists(source));
+    assertEquals("OLD", Files.readString(destination));
+    assertEquals(0, result.getResultFiles().size());
+  }
+
+  @Test
+  void decryptMoveSourceLeavesTheDestinationAndMovesTheSource() throws 
Exception {
+    Path source = file("d-move/sealed.gpg", "SEALED");
+    Path destination = file("d-move/out/sealed.gpg", "OLD");
+    Path moved = root.resolve("d-move/moved");
+    Files.createDirectories(moved);
+    ActionPGPDecryptFiles action =
+        decryptAction(ActionPGPDecryptFiles.CONST_MOVE_FILE, source, 
destination);
+    action.setDestinationFolder(moved.toString());
+    action.setCreateMoveToFolder(true);
+    Result result = action.execute(new Result(), 0);
+
+    assertTrue(result.isResult());
+    assertEquals(0, result.getNrLinesWritten());
+    assertEquals(0, result.getNrErrors());
+    assertFalse(Files.exists(source));
+    assertEquals("OLD", Files.readString(destination));
+    assertEquals("SEALED", Files.readString(moved.resolve("sealed.gpg")));
+    String registered = result.getResultFiles().keySet().iterator().next();
+    assertTrue(registered.contains("moved"), registered);
+    assertFalse(registered.contains("out"), registered);
+  }
+
+  @Test
+  void signSendsThePassphraseOnStdin() throws Exception {
+    Path source = file("sign/plain.txt", "PLAIN");
+    Path destination = root.resolve("sign/plain.txt.asc");
+    Files.createDirectories(destination.getParent());
+    ActionPGPEncryptFiles action = new ActionPGPEncryptFiles("sign");
+    action.setGpgLocation(stub.toString());
+    action.setDestinationIsAFile(true);
+    action.setCreateDestinationFolder(true);
+    action.setIfFileExists("overwrite_file");
+    attach(action);
+    ActionPGPEncryptFiles.PgpFile file = new ActionPGPEncryptFiles.PgpFile();
+    file.setActionType(ActionPGPEncryptFiles.ActionType.SIGN);
+    file.setLocalUser("[email protected]");
+    file.setPassphrase("secret");
+    file.setSourceFileFolder(source.toString());
+    file.setDestinationFileFolder(destination.toString());
+    action.getPgpFiles().add(file);
+
+    Result result = action.execute(new Result(), 0);
+
+    assertTrue(result.isResult());
+    assertEquals("PLAIN", Files.readString(destination));
+    assertEquals("secret", GpgCopyStub.standardInput(stub.getParent()));
+    List<String> args = GpgCopyStub.arguments(stub.getParent());
+    assertTrue(args.contains("--passphrase-fd"), args.toString());
+    assertTrue(args.contains("loopback"), args.toString());
+    assertFalse(args.contains("secret"), args.toString());
+  }
+
+  @Test
+  void aPreviousResultRowCarriesThePassphraseInTheSeventhField() throws 
Exception {
+    Path source = file("prev/plain.txt", "PLAIN");
+    Path destination = root.resolve("prev/sealed.asc");
+    Files.createDirectories(destination.getParent());
+    ActionPGPEncryptFiles action = new ActionPGPEncryptFiles("previous");
+    action.setGpgLocation(stub.toString());
+    action.setArgFromPrevious(true);
+    action.setDestinationIsAFile(true);
+    action.setCreateDestinationFolder(true);
+    action.setIfFileExists("overwrite_file");
+    attach(action);
+
+    RowMeta rowMeta = new RowMeta();
+    for (int i = 0; i < 7; i++) {
+      rowMeta.addValueMeta(new ValueMetaString("c" + i));
+    }
+    Result incoming = new Result();
+    incoming
+        .getRows()
+        .add(
+            new RowMetaAndData(
+                rowMeta,
+                new Object[] {
+                  "signandencrypt",
+                  source.toString(),
+                  "",
+                  "[email protected]",
+                  destination.toString(),
+                  "[email protected]",
+                  "secret"
+                }));
+
+    Result result = action.execute(incoming, 0);
+
+    assertTrue(result.isResult(), "errors=" + result.getNrErrors());
+    assertEquals("secret", GpgCopyStub.standardInput(stub.getParent()));
+    List<String> args = GpgCopyStub.arguments(stub.getParent());
+    assertTrue(args.contains("--passphrase-fd"), args.toString());
+    assertTrue(args.contains("[email protected]"), args.toString());
+    assertTrue(args.contains("[email protected]"), args.toString());
+  }
+
+  private ActionPGPEncryptFiles encrypt(String ifFileExists, Path source, Path 
destination) {
+    ActionPGPEncryptFiles action = new ActionPGPEncryptFiles("encrypt");
+    action.setGpgLocation(stub.toString());
+    action.setAddResultFileNames(true);
+    action.setDestinationIsAFile(true);
+    action.setCreateDestinationFolder(true);
+    action.setIfFileExists(ifFileExists);
+    attach(action);
+    ActionPGPEncryptFiles.PgpFile file = new ActionPGPEncryptFiles.PgpFile();
+    file.setActionType(ActionPGPEncryptFiles.ActionType.ENCRYPT);
+    file.setUserId("[email protected]");
+    file.setSourceFileFolder(source.toString());
+    file.setDestinationFileFolder(destination.toString());
+    action.getPgpFiles().add(file);
+    return action;
+  }
+
+  private Result decrypt(Path source, Path destination) throws Exception {
+    return decryptAction(ActionPGPDecryptFiles.CONST_DELETE_FILE, source, 
destination)
+        .execute(new Result(), 0);
+  }
+
+  private ActionPGPDecryptFiles decryptAction(String ifFileExists, Path 
source, Path destination) {
+    ActionPGPDecryptFiles action = new ActionPGPDecryptFiles("decrypt");
+    action.setGpgLocation(stub.toString());
+    action.setAddResultFilenames(true);
+    action.setDestinationIsAFile(true);
+    action.setCreateDestinationFolder(true);
+    action.setIfFileExists(ifFileExists);
+    attach(action);
+    ActionPGPDecryptFiles.FileToDecrypt file = new 
ActionPGPDecryptFiles.FileToDecrypt();
+    file.setSourceFileFolder(source.toString());
+    file.setDestinationFileFolder(destination.toString());
+    action.getFilesToDecrypt().add(file);
+    return action;
+  }
+
+  private static Path file(String relative, String content) throws Exception {
+    Path path = root.resolve(relative);
+    Files.createDirectories(path.getParent());
+    Files.writeString(path, content);
+    return path;
+  }
+
+  private static void attach(ActionBase action) {
+    WorkflowMeta meta = new WorkflowMeta();
+    meta.setName("pgp-test");
+    IWorkflowEngine<WorkflowMeta> workflow = new LocalWorkflowEngine(meta);
+    action.setParentWorkflow(workflow);
+  }
+}
diff --git 
a/plugins/actions/pgpfiles/src/test/java/org/apache/hop/workflow/actions/pgpencryptfiles/GpgArgumentPassingTest.java
 
b/plugins/actions/pgpfiles/src/test/java/org/apache/hop/workflow/actions/pgpencryptfiles/GpgArgumentPassingTest.java
index 8857ae9940..6006c21491 100644
--- 
a/plugins/actions/pgpfiles/src/test/java/org/apache/hop/workflow/actions/pgpencryptfiles/GpgArgumentPassingTest.java
+++ 
b/plugins/actions/pgpfiles/src/test/java/org/apache/hop/workflow/actions/pgpencryptfiles/GpgArgumentPassingTest.java
@@ -203,6 +203,50 @@ class GpgArgumentPassingTest {
     assertPassphraseOnStdinOnly("signAndEncrypt");
   }
 
+  @Test
+  void signFileSendsThePassphraseOverStdin() throws Exception {
+    gpg().signFile("plain.txt", "[email protected]", PASSPHRASE, 
"plain.txt.asc", true);
+    assertPassphraseOnStdinOnly("signFile");
+    assertLocalUser("[email protected]", "signFile");
+  }
+
+  @Test
+  void signFileWithoutAPassphraseAsksForNoFileDescriptor() throws Exception {
+    gpg().signFile("plain.txt", "[email protected]", "plain.txt.asc", true);
+    List<String> args = recordedArguments();
+    assertFalse(
+        args.contains("--passphrase-fd"),
+        "without a passphrase GnuPG must not be told to read one: " + args);
+    assertEquals("", recordedStdin(), "nothing must be written to stdin 
without a passphrase");
+  }
+
+  @Test
+  void signAndEncryptFileSendsThePassphraseOverStdin() throws Exception {
+    gpg()
+        .signAndEncryptFile(
+            "plain.txt",
+            "[email protected]",
+            "[email protected]",
+            PASSPHRASE,
+            "sealed.asc",
+            true);
+    assertPassphraseOnStdinOnly("signAndEncryptFile");
+    assertRecipient("[email protected]", "signAndEncryptFile");
+    assertLocalUser("[email protected]", "signAndEncryptFile");
+  }
+
+  @Test
+  void signAndEncryptFileWithoutAPassphraseAsksForNoFileDescriptor() throws 
Exception {
+    gpg()
+        .signAndEncryptFile(
+            "plain.txt", "[email protected]", "[email protected]", 
"sealed.asc", true);
+    List<String> args = recordedArguments();
+    assertFalse(
+        args.contains("--passphrase-fd"),
+        "without a passphrase GnuPG must not be told to read one: " + args);
+    assertEquals("", recordedStdin(), "nothing must be written to stdin 
without a passphrase");
+  }
+
   @Test
   void decryptFileSendsThePassphraseOverStdin() throws Exception {
     gpg().decryptFile("sealed.asc", PASSPHRASE, "opened.txt");
diff --git 
a/plugins/actions/pgpfiles/src/test/java/org/apache/hop/workflow/actions/pgpencryptfiles/GpgCopyStub.java
 
b/plugins/actions/pgpfiles/src/test/java/org/apache/hop/workflow/actions/pgpencryptfiles/GpgCopyStub.java
new file mode 100644
index 0000000000..c3133bb7a5
--- /dev/null
+++ 
b/plugins/actions/pgpfiles/src/test/java/org/apache/hop/workflow/actions/pgpencryptfiles/GpgCopyStub.java
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hop.workflow.actions.pgpencryptfiles;
+
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.Locale;
+import org.junit.jupiter.api.Assumptions;
+
+/**
+ * Stands in for {@code gpg}. Copies the file operand that follows {@code --} 
onto the {@code
+ * --output} path, and records the argument vector and standard input next to 
itself.
+ */
+final class GpgCopyStub {
+
+  private GpgCopyStub() {}
+
+  static Path install(Path directory) throws Exception {
+    Files.createDirectories(directory);
+    if 
(System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("win")) {
+      return compileWindows(directory);
+    }
+    return writeShell(directory);
+  }
+
+  static List<String> arguments(Path directory) throws Exception {
+    return Files.readAllLines(directory.resolve("args.txt"), 
StandardCharsets.UTF_8);
+  }
+
+  static String standardInput(Path directory) throws Exception {
+    return Files.readString(directory.resolve("stdin.txt"), 
StandardCharsets.UTF_8);
+  }
+
+  private static Path compileWindows(Path directory) throws Exception {
+    Path csc = 
Path.of("C:/Windows/Microsoft.NET/Framework64/v4.0.30319/csc.exe");
+    if (!Files.isRegularFile(csc)) {
+      csc = Path.of("C:/Windows/Microsoft.NET/Framework/v4.0.30319/csc.exe");
+    }
+    Assumptions.assumeTrue(Files.isRegularFile(csc), "csc.exe is required to 
build the GnuPG stub");
+    Path source = directory.resolve("GpgCopyStub.cs");
+    Path exe = directory.resolve("gpg-copy-stub.exe");
+    Files.writeString(source, windowsSource(), StandardCharsets.UTF_8);
+    Process process =
+        new ProcessBuilder(
+                csc.toString(), "/nologo", "/out:" + exe.toAbsolutePath(), 
source.toString())
+            .redirectErrorStream(true)
+            .start();
+    String output = new String(process.getInputStream().readAllBytes(), 
StandardCharsets.UTF_8);
+    int code = process.waitFor();
+    if (code != 0) {
+      throw new IllegalStateException("csc failed (" + code + "): " + output);
+    }
+    return exe;
+  }
+
+  private static Path writeShell(Path directory) throws Exception {
+    Path script = directory.resolve("gpg-copy-stub.sh");
+    Files.writeString(script, shellSource(), StandardCharsets.UTF_8);
+    script.toFile().setExecutable(true);
+    return script;
+  }
+
+  private static String shellSource() {
+    return """
+        #!/bin/sh
+        dir=$(CDPATH= cd -- "$(dirname "$0")" && pwd)
+        { for a in "$@"; do printf '%s\\n' "$a"; done; } > "$dir/args.txt"
+        out=
+        src=
+        while [ $# -gt 0 ]; do
+          case "$1" in
+            --output) out="$2"; shift 2 ;;
+            --) shift; src="$1"; break ;;
+            *) shift ;;
+          esac
+        done
+        if [ -n "$out" ] && [ -n "$src" ]; then
+          cp "$src" "$out"
+        fi
+        cat > "$dir/stdin.txt"
+        exit 0
+        """;
+  }
+
+  private static String windowsSource() {
+    return """
+        using System;
+        using System.IO;
+        using System.Text;
+        class GpgCopyStub {
+          static int Main(string[] args) {
+            string dir = Path.GetDirectoryName(
+                System.Reflection.Assembly.GetExecutingAssembly().Location);
+            File.WriteAllLines(Path.Combine(dir, "args.txt"), args);
+            string output = null;
+            string input = null;
+            for (int i = 0; i < args.Length; i++) {
+              if (args[i] == "--output" && i + 1 < args.Length) output = 
args[++i];
+              else if (args[i] == "--" && i + 1 < args.Length) {
+                input = args[i + 1];
+                break;
+              }
+            }
+            if (output != null && input != null) File.Copy(input, output, 
true);
+            using (var reader = new StreamReader(Console.OpenStandardInput(), 
Encoding.UTF8)) {
+              File.WriteAllText(Path.Combine(dir, "stdin.txt"), 
reader.ReadToEnd());
+            }
+            return 0;
+          }
+        }
+        """;
+  }
+}

Reply via email to