I have a requirement to decrypt the encrypted file that is place on a S3 bucket. PGP encryption is used to encrypt the file. Do I have to write a custom java code to decrypt the file using keys or is there any OOTB to decrypt the file?

    DineshKumar Hi Dinesh, We did it long before in our POC.
    We imported following opensource jars:

    1)bcpg-jdk15on-161.jar
    2)bcprov-jdk15on-161.jar
    3)commons-collections4-4.1.jar
    4)poi-3.6-20091214.jar
    5)poi-ooxml-3.6-20091214.jar
    6)poi-ooxml-schemas-3.6-20091214.jar
    7)poi-scratchpad-3.6-20091214.jar
    8)xmlbeans-2.6.0.jar

    The Javacode which we used in our activity ;

    Integer a,b;
    String s,filename;
    java.util.ArrayList<String> arrlist=new ArrayList<String>();
    org.apache.poi.xssf.usermodel.XSSFCell cell=null;
    int row_count=0;
    ClipboardProperty KeyValue=null;
    try{
      // ClipboardPage MyServicePage= tools.getStepPage();
       java.security.Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
       byte[] encryptedByteArray = new com.pega.pegarules.pub.util.Base64Util().decodeToByteArray(FileContent);
       byte[] decryptedByteArray = org.bouncycastle.openpgp.examples.ByteArrayHandler.decrypt(encryptedByteArray, pwd.toCharArray());
       FileContent=new com.pega.pegarules.pub.util.Base64Util().encodeToString(decryptedByteArray); 
      
    }catch(Exception e){
      oLog.error("Error processing PGP File" + e);
       e.printStackTrace();
    }

    Inputs: Local.FileContent - Filestream, Local.pwd - Password
    Returns : Local.FileContent - Filestream of decrypted file.

    Let us know if it helps in your scenario.

      2 years later

      Hi Sankar,

      is this code supports all the kind of files including csv and all.

        Write a Reply...

        -An Initiative Of OneStopPega- Love our work? Support Us🖤