SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


PGP - Encrypt and decrypt files through batch


PGP - Encrypt and decrypt files through batch

Author
Message
Tim Mitchell
Tim Mitchell
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1811 Visits: 2988
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


litsonjose 5315
litsonjose 5315
Grasshopper
Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)

Group: General Forum Members
Points: 15 Visits: 83
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...
a1_technology_geb
a1_technology_geb
SSC Rookie
SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)

Group: General Forum Members
Points: 35 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?
litsonjose 5315
litsonjose 5315
Grasshopper
Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)

Group: General Forum Members
Points: 15 Visits: 83
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
a1_technology_geb
a1_technology_geb
SSC Rookie
SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)

Group: General Forum Members
Points: 35 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.
pamela_hill
pamela_hill
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
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
Peter Schott
Peter Schott
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1491 Visits: 1919
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.
pamela_hill
pamela_hill
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
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
angeloadinolffi83
angeloadinolffi83
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 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]
adavys
adavys
Forum Newbie
Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: General Forum Members
Points: 7 Visits: 3
Hi Amy,

Like you I've spent 2 days trying to resolve this issue, the batch file runs perfectly when clicked on but does not produce the desired result when called from the SQL Agent job. Just wondering how you resolved this in the end?

Many thanks,

Ali
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search