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.
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.
@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?
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.
Create a standalone activity to test the library and set the required parameters.
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 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
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.
@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.