Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

PGP - Encrypt and decrypt files through batch Expand / Collapse
Author
Message
Posted Wednesday, May 18, 2011 8:06 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, July 10, 2014 8:41 AM
Points: 1,042, Visits: 2,714
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, SQL Server MVP
Independent Business Intelligence Consultant
www.TimMitchell.net
@Tim_Mitchell

Post #1111453
Posted Thursday, May 19, 2011 9:09 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, July 10, 2014 10:56 AM
Points: 5, Visits: 67
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...

Post #1111796
Posted Friday, July 8, 2011 3:19 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, July 29, 2011 5:53 PM
Points: 11, Visits: 85
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?
Post #1139258
Posted Friday, July 8, 2011 9:26 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, July 10, 2014 10:56 AM
Points: 5, Visits: 67
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
Post #1139305
Posted Saturday, July 16, 2011 2:53 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, July 29, 2011 5:53 PM
Points: 11, Visits: 85
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.
Post #1143002
Posted Thursday, April 18, 2013 3:46 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, April 19, 2013 12:06 PM
Points: 2, Visits: 3
Tim,
I noticed your posting on fully qualifying a command prompt pgp call. I did try that but am getting an error message that I can't see to find an explanation for...I'm wondering if my syntax is correct...any thoughts?
(I have additional parameters for the -decrypt but am wondering about the fully qualified command call??

\\servername\PGPdirectory\pgp.exe --decrypt "\\servername\ftproot\staging\filename"

error that I'm getting back is -1073741515
Thanks,
Pam
Post #1444179
Posted Friday, April 19, 2013 12:05 PM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Tuesday, July 22, 2014 3:47 PM
Points: 837, Visits: 1,259
Pam,
Off the top of my head, it looks like you're trying to run a remote PGP command. (based on you using \\servername\path\pgp.exe) In my experience, you likely need this installed and configured locally in order to get this to work. I can't speak to that specific error, but when we were using GnuPG (gpg.exe), we added it to the path and made sure that it could always find the keystore for the public/private keys that were needed. If you try to run the command on that machine, what happens? What happens when you run it as the service account?

I'm not sure how the official PGP software stores its keys, but that could play into the issues as well if those keys are stored per user as opposed to just on the server.



Post #1444551
Posted Friday, April 19, 2013 12:09 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, April 19, 2013 12:06 PM
Points: 2, Visits: 3
Peter,
Thanks for your prompt reply. Some of the research I did after this post indicates exactly what you are thinking. The command needs to run on the same server that PGP is installed on. I was trying to see if we could use a remote call; we are processing this from Tidal scheduling software and I recently learned that the Tidal agent has to be on the same server as the PGP install, so we will make changes to our setup and try this again.
Pam
Post #1444552
Posted Tuesday, December 24, 2013 9:44 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, December 24, 2013 9:44 AM
Points: 1, Visits: 1
LOOKING AT THIS LINK IS AN EXAMPLE OF HOW TO DO IT, COULD TAKE THE CODE AS AN EXAMPLE AND PUBLISH DLL DLL AND THEN THAT APPEAR ON YOUR PROJECT

[url=http://www.systemdeveloper.info/2013/11/decrypt-files-encrypted-with-gnupg-from.html][/url]
Post #1525778
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse