PGP - Encrypt and decrypt files through batch

  • I just installed PGP software on my machine. Now I want to use it, but not in the GUI interface provided. I'd like to type something like [pgp -s testpgp.txt] at a DOS prompt and have the file either encrypt or decrypt. I'm not able to find the exact command. Also, at the command line, it is giving me an error stating it cannot locate pgp.

    Can anyone help me assign or direct me to the write syntax to accomplish this?

    Thanks,

    Amy Welsh

    awelsh@welshkc.com

  • Where did you fire your command? Did you set the environmental variable?

  • I opened a command Prompt window and typed pgp -s filename.txt. No, I didn't set up the environment, which is why I suspect it is erroring stating it doesn't understand what pgp means.

    My company purchased PGP Desktop software that I should use to encrypt the data going between the client and I. I've used PGP before, and did it at the command line instead of through the GUI interface. I wanted to do that again.

    The PGP software is at c:\Program Files\PGP Corporation\PGP Desktop\PGPdesk.exe. But within this software, there are many options. I want the Zip function, and from the command line I'm not sure how to tell it what I expect.

    Any suggestions? I'm beginning to think the free pgp version would be easier to use in this fashion than PGP Desktop.

    Amy

  • awelsh (7/9/2008)


    I opened a command Prompt window and typed pgp -s filename.txt. No, I didn't set up the environment, which is why I suspect it is erroring stating it doesn't understand what pgp means.

    My company purchased PGP Desktop software that I should use to encrypt the data going between the client and I. I've used PGP before, and did it at the command line instead of through the GUI interface. I wanted to do that again.

    The PGP software is at c:\Program Files\PGP Corporation\PGP Desktop\PGPdesk.exe. But within this software, there are many options. I want the Zip function, and from the command line I'm not sure how to tell it what I expect.

    Any suggestions? I'm beginning to think the free pgp version would be easier to use in this fashion than PGP Desktop.

    Amy

    Amy, it appears that you have two different issues - first, you're calling PGP.exe but your environment doesn't know where to find this file, and second, you're not able to use the command line options you want.

    For the first issue, you either need to set the environmental variable as the first respondent suggested, or use the full path to call PGP.exe (rather than just calling it by file name). I recommend the latter, particularly if you plan on moving your package from one machine to another.

    The second issue is not really an SSIS issue but a PGP issue. I've used PGP a couple of times in SSIS packages but I can't tell you exactly what the command line parameters are. From the command line, enter the path to the PGP executable and use the Help parameter, which will normally be /? or -help. The output should explain file usage.

    Hope this helps...

    Tim

    Tim Mitchell, Microsoft Data Platform MVP
    Data Warehouse and ETL Consultant
    TimMitchell.net | @Tim_Mitchell | Tyleris.com
    ETL Best Practices

  • Thanks Tim. That gets me farther.

    I haven't figured out the parameters to pass yet. Each time I type the executable name, the software interface pops up instead of giving me a list of help topics that I'd prefer.

    I'll keep playing around with it.

    Thanks again for the response!

    Amy

  • Amy, if you're entering the executable name and the graphical tool is coming up, you're calling the wrong executable. There will be a different EXE file for command-line usage. In the version that I have used (which is an older version), the command line executable was pgp.exe.

    Hope this helps...

    Tim

    Tim Mitchell, Microsoft Data Platform MVP
    Data Warehouse and ETL Consultant
    TimMitchell.net | @Tim_Mitchell | Tyleris.com
    ETL Best Practices

  • Hello Tim,

    My problem is in decryption part.

    I have set the pgp environment, passed the arguments, set the working folder. When i run the SSIS package from development environment , the decryption process is running perfectly. But, when i try to call the same SSIS package from a stored procedure (SQL SERVER) , I am getting an error and the file is not decrypting. I am sure my batch file is executing because before the decrypt command i am deleting an exsisitng file. Only problem is in this command

    echo *******| gpg --passphrase-fd 0 --decrypt-files "\Files_Import\FTP\%1.txt.pgp"

    The error msg is "The process exit code was "2" while the expected was "0"."

    waiting for the reply......

  • litsonjose,

    I've not used the GPG tool specifically - when I need command line en/decryption, I've used PGP in the past. However, on the PGP command line there is a text prompt that you must confirm the first time you use the executable, and this must be done at the user level (a prompt to add the key to the cache, if I'm not mistaken). There was a "silent mode" that would suppress this prompt and continue execution.

    Since the command line app works under your login but not as a scheduled job, I suspect that your problem is probably similar to what I found with PGP. Look in the GPG product documentation or help commands to see if there is a silent mode to suppress prompts. Alternatively, you might log into the server as the account that executes the job and try to run the command line app manually - you may be able to override the prompt there.

    hth,

    Tim

    Tim Mitchell, Microsoft Data Platform MVP
    Data Warehouse and ETL Consultant
    TimMitchell.net | @Tim_Mitchell | Tyleris.com
    ETL Best Practices

  • Hello Tim,,

    Is that error any thing related to the permission of sql server ? I created an Sql job which executed the batch file. The batch file has the code to decrypt the gpg file . Below is the code

    echo test| gpg --passphrase-fd 0 --decrypt files "F:\folder\FTP\DL-8153015-20110518.txt.pgp"

    "test" is the passphase.

    When i execute this batch file from sql server agent , i am getting this error log :

    C:\Windows\system32> echo test| gpg --passphrase-fd 0 --decrypt files "F:\folder\FTP\DL-8153015-20110518.txt.pgp"

    gpg: encrypted with ELG-E key, ID 2AADDF95

    gpg: decryption failed: secret key not available

    Why it saying secret key not available. the "test" is the secret key and this same command run perfectly in command prompt. Why not in sqlserver agent or from sql sp's...

    I think its some thing to do with permission level in sql server. Because the decrypt uses the private key and need full system environment... What's your solution.. Can you advice.. I am stuck up with this issue for 2 days....My system is 64bit , os is vista. GnuPG - The GNU Privacy Guard Version 1.4.11

  • Hi Amy,

    You could try this to redirect display to nowhere:

    gpg --<your gpg parameters> > nul

    or to a file:

    gpg --<your gpg parameters> > path\filename

  • I doubt that the issue is with SQL Server permissions. Again, I suspect your encryption software (GPG). I'd recommend running through their documentation (or support forums, if they have them) to try to identify a fix.

    Tim Mitchell, Microsoft Data Platform MVP
    Data Warehouse and ETL Consultant
    TimMitchell.net | @Tim_Mitchell | Tyleris.com
    ETL Best Practices

  • Hello Tim,

    The issue is with the permission. The problem is with decrypting file, and for that i have to use the private key - public key combination . This process takes the OS environment and depending only on SQL Agent and SSIS package may not work. I solve the porblem by adding one more layer. Instead of using Process Task in SSIS package which execute the batch file to encrpt file, I am using a Script task which is referenced to a Web Service. All the gpg decrypt command is exceted from the webservice using c# process class " System.Diagnostics.ProcessStartInfo procStartInfo =

    new System.Diagnostics.ProcessStartInfo("cmd", "/c " + cmd);"

    where "cmd" is the gpg decrypt command line. This way web sevice have the access to the OS environment.

    The process starts from SQL service agent which calls the Stored Procedure (for getting file name) which calls the SSIS Package (using xp_cmdshell and pass file name to SSIS package). In the SSIS Package the Script Task will create the webservice object and excute the decrypt method from the webservice.

    Thanks for your time and reply...

  • Hey, Tim

    I have similar question I am attempting to implement the same decryption batch process for importing data. I am using the commandline only version of pgp 10.1.0. I know the execution of the decryption/encryption step is relative to the home directory, so if the keys are not in the home directory likely (My Documents) or the current working directory is not the home directory you won't be able to successfully execute the process.

    decrypting at the command line is some ting like >pgp --decrypt path\filename.pgp --passphrase "yourpassphrase"

    My issue, I want to know if anyone has done this using xp_cmdshell.

    I believe i need to cd into my pgp home directory and then execute the full path to the pgp.exe in program files\* directory.

    but i can't change directory using xp_cmdshell. Anyone know of a workaround\fix\alternative?

  • hello,

    Use my above post.

    I too came across the same problem in my decryption process. Because for decryption, the gpg uses the full OS environment. (Looking for public key private key combination). In gpg, the private key is stored outside the application folder.

    When i tried to decrypt the file using xp_cmdshell (xp_cmdshell executes a SSIS package which has a batch executable task for decrypt file) . I could not decrypt in this manner.

    I solved by creating a webservice (.net) and in that i used a web method to decrypt the file. As the webservice executes out side the sql server environment, service gets full OS environment.

    This way i replaced the batch excutable task from SSIS package to Script task. Script task gets the object of webservice and calls the decrypt method.

    my entire decryption process starts from sql server job -> call sql stored procedure -> sp has xp_cmdshell which calls the SSIS package.

    Thanks

  • Thanks for the input.

    Actually, i was able to get going by using .bat files to call the pgp command. Instead of trying to use the cd command inside the xp_cmdshell 'cd\ fullpath-to-\pgp.exe --decrypt filename.pgp -o j:\directory-to-put-file-in\'

    decryption wound up being something like:

    inside x.bat file

    cd

    pgp.exe '--decrypt "filename.pgp" -o "j:\directory-to-put-file-in\" --passphrase "passphrase"'

    encrypt would be

    cd

    pgp.exe '-er "recipient-enrypted-to" encrypted-filename.csv'

    Ed B.

Viewing 15 posts - 1 through 15 (of 20 total)

You must be logged in to reply to this topic. Login to reply