Command Line

Expand all | Collapse all

PGP command line encryption in Java

  • 1.  PGP command line encryption in Java

    Posted 02-11-2021 03:30 PM
    Hi All,

    I am trying to call PGP command line encryption from Java but unable to execute the command.
    Change in command gives different error:
    pgp -es <filenname> --output <outputfile> -r <RecipientKey> --signer <Signer> --passphrase <Passphrase>
    This is throwing error 162

    However, when I tried to use similar command for Decryption, it worked. (Initially throwing same error- Then I added output file name in command)
    pgp --decrypt <filename> --output <outputfile> --passphrase <Passphrase>

    Can someone please help me get correct command - used below two commands till now:
    1. pgp -es <filenname> --output <outputfile> -r <RecipientKey> --signer <Signer> --passphrase <Passphrase>

    2. pgp -es <filenname> -r <RecipientKey> --signer <Signer> --passphrase <Passphrase>

    3. pgp -encrypt <filenname> --output <outputfile> -recipient <RecipientKey> --signer <Signer> --passphrase <Passphrase>

    Thanks !!

  • 2.  RE: PGP command line encryption in Java

    Broadcom Employee
    Posted 02-11-2021 04:28 PM

    It's hard to say what's going on here.  When executing from a script make sure you test the commands from the command line first.  It's often useful to have have the script output the command it would have run to stdout and then run it manually to make sure that the syntax is coming through your parser correctly.  If you can run the exact same command manually from the command line and it won't run in your program it's almost certainly an environment problem.  This is probably the case, the syntax you posted for the commands you are running seems valid.  Check the environment in your script and make sure that the environment is the same as the command line.  I would suggest running pgp --version --verbose from the script, it will show you a lot of config options like what home directory it is using and what keyrings it is using.  I would suspect that it is loading a default config file rather than the config file you expect or something like that, based on what environment the script has.  Without the output of the command it's difficult to say what the exact cause is, I can tell you that return code 162 is "Encode - Complete failure during an encode." but that can be many root causes (key doesn't exist, file doesn't exist, etc).  If you can capture what the executable is trying to print out during the operation it would be helpful in narrowing down the exact cause.

  • 3.  RE: PGP command line encryption in Java

    Posted 02-14-2021 08:56 PM
    Hi Josh,

    Thank for your response.
    I have my printed command on console and used the same to verify (by running on terminal directly, to make sure no spaces or incorrect spelling)
    Everything worked fine but the key(as you suspected)  was wrong.
    The key shared with me was wrong (typo mistake) and hence it was giving 162 error.

    I thank you again for your valuable time and inputs.

    Also, to others, who would try similar in future, can use the commands. All are working fine.

    Thanks !!!