NetTalk Central

Author Topic: PGP Encryption  (Read 9188 times)

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
PGP Encryption
« on: March 16, 2014, 05:38:32 PM »
Hi All,

I have a new client that wants a csv file PGP encrypted before FTPing it to their site. They have sent me a public key with an asc extension. Is this possible? My program runs on a 64bit windows 2008 server.

Cheers,

Kevin

Jane

  • Sr. Member
  • ****
  • Posts: 372
  • Expert on nothing with opinions on everything.
    • View Profile
    • Email
Re: PGP Encryption
« Reply #1 on: March 16, 2014, 06:32:43 PM »
Sure, it's possible.

Nothing to do with NetTalk, but I have a SQL Agent job that runs a Clarion program on a 64-bit Server2008 R2 machine to create a text file (not CSV, but some weird delimiters which is why I didn't use SSIS).

It was a bit of a challenge finding a cheap (or in this case, free) command-line PGP client. 

I wound up using gpg2.exe.

The program and all its DLLs are in a folder used by my job.
After creating the text file, my program runs a batch file with one line:

gpg2 --homedir . -r client6 -a -o %1 -e %2

Then I run another batch file that calls WinSCP (a free SFTP program) to upload it.

I set this up about a year ago, so details are very fuzzy.  There was some twiddling with getting keys into trustdb.gpg.
If I run gpg2 --list-public-keys --homedir .
It shows that "client6" is the uid in the trustdb file in the folder I'm using.

It's been running every night since then.

Jane

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: PGP Encryption
« Reply #2 on: March 17, 2014, 06:02:29 AM »
Thanks Jane - this is exactly what I need.

Cheers,

Kevin

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: PGP Encryption
« Reply #3 on: March 19, 2014, 07:51:43 AM »
Hi Jane,

I downloaded winscp and can transfer a file using the onscreen gui. When I try to use the following in my app I always get an error. I also tried to put the following in a script file but still no joy. I'm not sure what I'm doing wrong.

RUN('c:\winscp\winscp.exe /command <34>option batch abort<34> <34>option confirm off<34> <34>open sftp://' & Clip(L:User) & ':' & Clip(L:Pass) & '@' & Clip(L:IPAddress) & '/<34> <34>put ' & Clip(L:FileName3) & ' ' & Clip(L:Directory) & '<34> <34>exit<34>',1)

L:Directory = '/Inbound/' but I have also tried various combinations

any tips?

Cheers,

Kevin

Jane

  • Sr. Member
  • ****
  • Posts: 372
  • Expert on nothing with opinions on everything.
    • View Profile
    • Email
Re: PGP Encryption
« Reply #4 on: March 19, 2014, 08:13:34 AM »
Hi, Kevin,

Bearing in mind that we're just talking about the SFTP part of the process... I've PGP encrypted the file first.

Also... when I first set up an SFTP to a site, I'll normally connect manually first.  A lot of times you get a "do you want to install this site's certificate" message.

My SFTP upload is two pieces.

There's a batch file, which reads:
"C:\Program Files (x86)\WinSCP\WinSCP.com" /script=c:\340b\Walgreen\WalgreenWinSCPscript.txt  /log=c:\340b\Walgreen\Walgreens.log

And the script file it calls consists of:
option batch abort
option confirm off
open Walgreens
option transfer binary
lcd c:\340b\walgreen
put -nopermissions -nopreservetime c:\340b\Walgreen\OutputData\9310*.pgp *.pgp
close
exit

The "open Walgreens" is opening a site I've saved in WinSCP called Walgreens.

At least one other tweak I remember is needing to tell WinSCP to store its sites setup in an INI file rather than in the registry (since I'm running this as SQL Agent, not as a logged on user.)  Pic attached.

You may also find this useful:
http://winscp.net/eng/docs/guide_automation

Cheers,

Jane







[attachment deleted by admin]

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: PGP Encryption
« Reply #5 on: March 19, 2014, 03:28:39 PM »
Thanks Jane that really helped - I can now get a file into the root folder but can't work out how to get it into the /Inbound/ folder. Still trying a few different combinations...

<34>put -nopermissions -nopreservetime  ' & Clip(L:FileName3) & ' /Inbound/<34>

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: PGP Encryption
« Reply #6 on: March 19, 2014, 06:16:51 PM »
I finally found the lucky combination Inbound/

The docs and examples are a bit sketchy but it's a neat program that does what I want so thanks a million again for all your help Jane!

Stu

  • Hero Member
  • *****
  • Posts: 510
    • View Profile
    • Email
Re: PGP Encryption
« Reply #7 on: March 19, 2014, 06:24:56 PM »
Awesome post, this should definitely get copied into the "Share Knowledge" forum .. Any mods able to do this?
Cheers,

Stu Andrews