PGP Encryption of documents in Pega - Solution

Hi All,

we saw multiple people were looking for solution for implementing PGP encryption in Pega for documents.

Hi All, if you are looking for solution of PGP(Preety Good Privacy) Encryption of documents(PDF, Word, XML, CSV & etc) in Pega. Here is the solution. First of all you need Bouncy Castle Crypto library in Pega. if your already on 8.7 version then all the bouncy castle libraries are available in pega except “org.bouncycastle.util.io.Streams”. we cretaed a java project for encryption and decryption using bouncy castle library. and created a jar for that which include this missing steram class as well. we have attached that jar file in attachments, please deploy the attached jar file in to your pega server. then create a library(PGPCryptoLibrary) and java function(EncryptionDecryption) in that library with 5 string parameters. Parametes decription is given below.

Encrypt
String inputFileName = “Source File Location on Server with name and extension of file”
String outputFileName = “Location where you want to put Encrypted file with name and extension on same server” String encKeyFileName = “Location of Public Key with name and extension of file on server”
String passwd = “” – No password required for Encryption
String Mode = “Encrypt”

Decrypt
String inputFileName = “Source Encrypted File Location on Server with name and extension of file”
String outputFileName = “Path where you want to put decrypted file on same server” – Only path is required as decryption function will decrypt the file with original file name.
String encKeyFileName = “Location of Provate Key with name and extension of file on server”
String passwd = “Password” – Password for Decryption
String Mode = “Decrypt”

Then check the attached java code file in attachment and paste the code in “EncryptionDecryption” java function that you have already created.

  • Check the Function Ready to be Compiled Check box
  • Click on Test Function Compilation
  • Click on Generate Function
  • Click on Generate Library Now you can call this function any where and pass parameters according to your requirement.

Pega Java Code.txt (1.4 KB)

PGP_Final.zip (8.23 KB)

@VishantC wow so much informative article. Please do share for other topics also.

Many thanks for your detailed post.

Also note that there may be a Marketplace offering which could help users looking for another method of encryption.

See my response in PGP encryption in pega for files

@VishantC

Hi Vishant,

Hope you are doing well, I have tried to implement the above solution to encrypt and decrypt the file which is already in a location.

Imported the library and created the java function. I have passed the parameters as you suggested above. I am trying to encrypt a file which is in a file location and want to save the encrypted file in the same location with a different file name using the java function. I am getting file not found exception in the logs on new file name which I gave in the parameter as source output.

I have done this exercise using file data sets and it is working as expected. But, I want to try this using your customized solution in a activity.

Can you please help me here or anyone who has implemented this one.

Thanks in Advance.

Dileep

@VishantC

Thanks vishant for the solution and it really helped.

Regards

Dileep Kumar Balaga

@VishantC Thanks for sharing the custom solution you put to encrypt files. I don’t see any jar file attachment. Can you please share the jar you created?

@Harshil8888Hi Harshil,

Can you try Arun Sarkar’s solution as he was also trying to configure in 24 version. i guess he was also facing similar issue. try to Installed bcprov-jdk18on-1.80.jar in Tomcat and check.

@VishantC Thank you for the detailed steps. We have implemented and it worked. We have to sign the file additionally using PGP, Have you tried this?

Thanks

Guhan

Hi @DileepBalaga,

Can you please mention the detailed steps on how to implement this using data sets.

Thanks in advance
Harshil

@DileepBalaga , I am facing same error.Did you find any solution for this?If so,can you let us know.

@DileepBalaga Most Welcome Dileep :slight_smile: it was nice to work with you.

@jwalak58

Hi Jwala,

Please check the logs, you will get the exact error. please share the logs with us as well.

@VishantC I tried importing the zip file provided, but getting error as

  • pyArchiveType: The selected archive is invalid or of an unknown type. Please validate archive type or select another file to import.

Kindly help us here.

@AhalyaK9extract the zip file and install the jar

@VishantC Hi Vishant,

Trying this approach in v24.2.1.

Steps followed:

  1. Import JAR file

  2. Created library without any issues.

  3. Create a standalone activity to test the library and set the required parameters.

  4. While running getting below error:

Caused by: java.lang.ClassNotFoundException: org.bouncycastle.jce.provider.BouncyCastleProvider 
	at com.pega.pegarules.internal.bootstrap.phase2.PRBaseLoader.findClass(PRBaseLoader.java:324) ~[?:?] 
	at java.lang.ClassLoader.loadClass(ClassLoader.java:592) ~[?:?] 
	at com.pega.pegarules.internal.bootstrap.phase2.PRBaseLoader.loadClass(PRBaseLoader.java:249) ~[?:?] 
	at java.lang.ClassLoader.loadClass(ClassLoader.java:525) ~[?:?] 

Error in java step :

org.bouncycastle.openpgp.examples.KeyBasedFileProcessor.encryptFile(
outputFileName, inputFileName, encKeyFileName, armor, withIntegrityCheck);

Do we need to import any other JAR’s or something needs to be configured is pega instance. Please check and let me know.

Thanks

Arun Sankar

@VishantCHi Vishant,

Trying this approach in v24.2.2

Steps followed:

  1. Imported JAR file

  2. Created library without any issues.

  3. Create function with the provided java code and add the 5 parameters

  4. Create a standalone activity to test the function and set the required parameters.

  5. While running getting below error:

Error - 127.0.0.1: com.pega.pegarules.pub.PRRuntimeError

Error at Java step - org.bouncycastle.openpgp.examples.KeyBasedFileProcessor.encryptFile(outputFileName, inputFileName, encKeyFileName, armor, withIntegrityCheck);

Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.bouncycastle.openpgp.examples.KeyBasedFileProcessor at com.pegarules.generated.EncryptionDecryption2_010101__6446954152874903890.EncryptionDecryption201_01_01(EncryptionDecryption2_010101__6446954152874903890.java:140)
Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.NoSuchFieldError: id_hmacWithSHA512_224 [in thread “https-jsse-nio-9443-exec-6”] at org.bouncycastle.jcajce.provider.digest.SHA512$Mappings.configure(Unknown Source) at org.bouncycastle.jce.provider.BouncyCastleProvider.loadServiceClass(Unknown Source)

Can you provide your inputs in what could be the actual issue

Thanks,
Harshil Rindani

@PanimozhipavaiT16739463 @GuhanathanV4521

We have recently implemented it again in cloud 3, not sure about pega 24 but in cloud 3 java is upgraded and its java 11 now. And it is working fine in cloud 3. we did some workaround to use the same jar in cloud 3. Please let me know if anyone is facing issue after upgrading to cloud 3.

@jwalak58

Hi,

I have tried the solution which was mentioned by vishant and it did worked.

In the beginning I faced issues with Jar and Java code.. After multiple retry the code worked.

Please attach the error logs you are facing.

Thanks

Dileep Kumar Balaga

@PHANIP32

I have attached the file.

@VishantC ,We couldn’t make it work in cloud infrastructure as pega doesn’t allow third party classes to access/create files in cloud location.Any idea,If anyone implemented PGP in pega cloud environments.