We help IT Professionals succeed at work.
Get Started

Decrypting a PGP file in UNIX using java

joe_suganth
joe_suganth asked
on
1,489 Views
Last Modified: 2012-05-12
I have a file "Sample.DAT.txt" which is decrypted by PGP.
Inwindows by replacing the ".txt" extension with ".com"  which when double  clicked opens the "PGP Self Decrypting Archive - Enter passphrase" window,
where i enter the passphrase and click OK creates a "Sample.DAT" . This file when appended with the ".txt"
extension gives me the required decrypted file.


I'm using JAVA running in Window's to execute all this with the below code.

            String cmd = FileToBeDecrypted; // ".com" file which has to be decrypted
            Runtime run = Runtime.getRuntime();
            Process pr = run.exec(cmd);
            
            
            Robot robot = new Robot();  
            robot.delay(5000);
              
                  robot.keyPress(KeyEvent.VK_SHIFT);
            robot.keyPress(KeyEvent.VK_TAB);

            robot.keyRelease(KeyEvent.VK_SHIFT);
            robot.keyRelease(KeyEvent.VK_TAB);

            robot.keyPress(KeyEvent.VK_SHIFT);
            robot.keyPress(KeyEvent.VK_TAB);

            robot.keyRelease(KeyEvent.VK_SHIFT);
            robot.keyRelease(KeyEvent.VK_TAB);
            
            //KeyPress and KeyRelease events for specifying the detination path

            robot.keyPress(KeyEvent.VK_TAB);

            robot.keyRelease(KeyEvent.VK_TAB);

            robot.keyPress(KeyEvent.VK_TAB);

            robot.keyRelease(KeyEvent.VK_TAB);

            //KeyPress and KeyRelease events for specifying the passphrase
 
                  robot.keyPress(KeyEvent.VK_TAB);
            robot.keyRelease(KeyEvent.VK_TAB);
            robot.keyPress(KeyEvent.VK_ENTER);
            robot.keyRelease(KeyEvent.VK_ENTER);                              
            robot.delay(5000);


And now we are in the position to move the logic from Window's based JAVA to UNIX based Java ...
I'm using the below code to replicate the same action.

            sExe = "pgp"
                       + " --decrypt "
                       + " "
                       + inputfile                  
                       + " --symmetric-passphrase "
                       + "passphrase"
                       + " --output "
                       + outputFile;
            Runtime run = Runtime.getRuntime();
            Process pr = run.exec(sExe);
      
            //inputfile---> "Sample.DAT.pgp" (Replacing ".txt" with ".pgp" from the original encrypted file "Sample.DAT.txt")
            //outputfile---> "Sample.DAT"

But it throws some error's,

      java.io.IOException: java.io.IOException: pgp: not found

while running the code

Pelase let me know how to decrypt the file in UNIX based Java?
Comment
Watch Question
Awarded 2011
Awarded 2011
Commented:
This problem has been solved!
Unlock 1 Answer and 42 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE