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

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


The following commit(s) were added to refs/heads/main by this push:
     new 913a389dfd6 NIFI-16384 Replaced deprecated PGP Decryptor usage with 
Key Pair (#11723)
913a389dfd6 is described below

commit 913a389dfd6eb8945b94f0951b92be661207f002
Author: David Handermann <[email protected]>
AuthorDate: Mon Sep 28 02:57:57 2026 -0500

    NIFI-16384 Replaced deprecated PGP Decryptor usage with Key Pair (#11723)
---
 .../org/apache/nifi/processors/pgp/DecryptContentPGP.java     | 11 ++++++++++-
 .../org/apache/nifi/processors/pgp/EncryptContentPGPTest.java | 10 +++++++++-
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git 
a/nifi-extension-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/main/java/org/apache/nifi/processors/pgp/DecryptContentPGP.java
 
b/nifi-extension-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/main/java/org/apache/nifi/processors/pgp/DecryptContentPGP.java
index 7252a3ab555..618242355a2 100644
--- 
a/nifi-extension-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/main/java/org/apache/nifi/processors/pgp/DecryptContentPGP.java
+++ 
b/nifi-extension-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/main/java/org/apache/nifi/processors/pgp/DecryptContentPGP.java
@@ -44,22 +44,27 @@ import 
org.apache.nifi.processors.pgp.exception.PGPDecryptionException;
 import org.apache.nifi.processors.pgp.exception.PGPProcessException;
 import org.apache.nifi.util.StringUtils;
 import org.bouncycastle.bcpg.KeyIdentifier;
+import org.bouncycastle.bcpg.PublicKeyPacket;
 import org.bouncycastle.openpgp.PGPCompressedData;
 import org.bouncycastle.openpgp.PGPEncryptedData;
 import org.bouncycastle.openpgp.PGPEncryptedDataList;
 import org.bouncycastle.openpgp.PGPException;
+import org.bouncycastle.openpgp.PGPKeyPair;
 import org.bouncycastle.openpgp.PGPLiteralData;
 import org.bouncycastle.openpgp.PGPObjectFactory;
 import org.bouncycastle.openpgp.PGPPBEEncryptedData;
 import org.bouncycastle.openpgp.PGPPrivateKey;
+import org.bouncycastle.openpgp.PGPPublicKey;
 import org.bouncycastle.openpgp.PGPPublicKeyEncryptedData;
 import org.bouncycastle.openpgp.PGPUtil;
 import org.bouncycastle.openpgp.jcajce.JcaPGPObjectFactory;
+import org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator;
 import org.bouncycastle.openpgp.operator.PBEDataDecryptorFactory;
 import org.bouncycastle.openpgp.operator.PublicKeyDataDecryptorFactory;
 import org.bouncycastle.openpgp.operator.bc.BcPBEDataDecryptorFactory;
 import org.bouncycastle.openpgp.operator.bc.BcPGPDigestCalculatorProvider;
 import org.bouncycastle.openpgp.operator.bc.BcPublicKeyDataDecryptorFactory;
+import org.bouncycastle.openpgp.operator.jcajce.JcaKeyFingerprintCalculator;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -417,7 +422,11 @@ public class DecryptContentPGP extends AbstractProcessor {
                 final Optional<PGPPrivateKey> foundPrivateKey = 
privateKeyService.findPrivateKey(keyId);
                 if (foundPrivateKey.isPresent()) {
                     final PGPPrivateKey privateKey = foundPrivateKey.get();
-                    final PublicKeyDataDecryptorFactory decryptorFactory = new 
BcPublicKeyDataDecryptorFactory(privateKey);
+                    final KeyFingerPrintCalculator keyFingerPrintCalculator = 
new JcaKeyFingerprintCalculator();
+                    final PublicKeyPacket publicKeyPacket = 
privateKey.getPublicKeyPacket();
+                    final PGPPublicKey publicKey = new 
PGPPublicKey(publicKeyPacket, keyFingerPrintCalculator);
+                    final PGPKeyPair keyPair = new PGPKeyPair(publicKey, 
privateKey);
+                    final PublicKeyDataDecryptorFactory decryptorFactory = new 
BcPublicKeyDataDecryptorFactory(keyPair);
                     final int symmetricAlgorithm = 
publicKeyEncryptedData.getSymmetricAlgorithm(decryptorFactory);
                     setSymmetricKeyAlgorithmAttributes(symmetricAlgorithm);
                     return 
publicKeyEncryptedData.getDataStream(decryptorFactory);
diff --git 
a/nifi-extension-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/test/java/org/apache/nifi/processors/pgp/EncryptContentPGPTest.java
 
b/nifi-extension-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/test/java/org/apache/nifi/processors/pgp/EncryptContentPGPTest.java
index 8b0ab82ce8f..b68db67bb25 100644
--- 
a/nifi-extension-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/test/java/org/apache/nifi/processors/pgp/EncryptContentPGPTest.java
+++ 
b/nifi-extension-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/test/java/org/apache/nifi/processors/pgp/EncryptContentPGPTest.java
@@ -28,10 +28,12 @@ import org.apache.nifi.util.MockFlowFile;
 import org.apache.nifi.util.TestRunner;
 import org.apache.nifi.util.TestRunners;
 import org.bouncycastle.bcpg.ArmoredInputStream;
+import org.bouncycastle.bcpg.PublicKeyPacket;
 import org.bouncycastle.openpgp.PGPCompressedData;
 import org.bouncycastle.openpgp.PGPEncryptedData;
 import org.bouncycastle.openpgp.PGPEncryptedDataList;
 import org.bouncycastle.openpgp.PGPException;
+import org.bouncycastle.openpgp.PGPKeyPair;
 import org.bouncycastle.openpgp.PGPLiteralData;
 import org.bouncycastle.openpgp.PGPObjectFactory;
 import org.bouncycastle.openpgp.PGPPBEEncryptedData;
@@ -41,12 +43,14 @@ import org.bouncycastle.openpgp.PGPPublicKeyEncryptedData;
 import org.bouncycastle.openpgp.PGPSecretKey;
 import org.bouncycastle.openpgp.PGPSecretKeyRing;
 import org.bouncycastle.openpgp.jcajce.JcaPGPObjectFactory;
+import org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator;
 import org.bouncycastle.openpgp.operator.PBEDataDecryptorFactory;
 import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor;
 import org.bouncycastle.openpgp.operator.PublicKeyDataDecryptorFactory;
 import org.bouncycastle.openpgp.operator.bc.BcPBEDataDecryptorFactory;
 import org.bouncycastle.openpgp.operator.bc.BcPGPDigestCalculatorProvider;
 import org.bouncycastle.openpgp.operator.bc.BcPublicKeyDataDecryptorFactory;
+import org.bouncycastle.openpgp.operator.jcajce.JcaKeyFingerprintCalculator;
 import 
org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.BeforeEach;
@@ -327,7 +331,11 @@ public class EncryptContentPGPTest {
     private byte[] getDecryptedData(final PGPPublicKeyEncryptedData 
publicKeyEncryptedData,
                                     final PGPPrivateKey privateKey,
                                     final DecryptionStrategy 
decryptionStrategy) throws PGPException, IOException {
-        final PublicKeyDataDecryptorFactory decryptorFactory = new 
BcPublicKeyDataDecryptorFactory(privateKey);
+        final KeyFingerPrintCalculator keyFingerPrintCalculator = new 
JcaKeyFingerprintCalculator();
+        final PublicKeyPacket publicKeyPacket = 
privateKey.getPublicKeyPacket();
+        final PGPPublicKey publicKey = new PGPPublicKey(publicKeyPacket, 
keyFingerPrintCalculator);
+        final PGPKeyPair keyPair = new PGPKeyPair(publicKey, privateKey);
+        final PublicKeyDataDecryptorFactory decryptorFactory = new 
BcPublicKeyDataDecryptorFactory(keyPair);
         final InputStream decryptedDataStream = 
publicKeyEncryptedData.getDataStream(decryptorFactory);
         return getDecryptedData(decryptedDataStream, decryptionStrategy);
     }

Reply via email to