Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VFP7 + PGP Encryption

Status
Not open for further replies.

IForgotAgain

Programmer
Sep 20, 2005
12
0
0
US
I have done a Search for PGP encryption within these VFP forums and have found a couple general references to using the VFP _crypt.vcx class.

But I have not found any specific code samples of how to make this happen.

I have used FOPEN() to create a Text file from a VFP data table and I have been given a Public PGP key to use (not any default key).

I am doing the programming in a PRG/FXP file and not in a Form since this will occur automatically with no user input.

Now how do I bring it all together to end up with an PGP encrypted text file (using the supplied PGP key .ASC file)?

Your advice would be most welcome.

Thanks,
I_Forgot_Again
 
Use the NSDPGP3 library written by Gerard Thomas. I've used it successfully in every version of VFP from 7 through 9.

It is a COM wrapper for implementing PGP version 8.0. I don't know if it will work with later versions. There is an older version, NSDPGP2, that I think works with earlier versions of PGP. Oh, and it also works with the GNU version, called GPG.

My documentation says it's available at

It uses the keyring file so the ASC key you have will need to be imported into the keyring.

It has lots of methods - the only ones I use are encrypt(), decrypt() and the method for retrieving the key from the keyring given the email address of the recipient.

Post back if you have questions once you begin to work with it.


Mike Krausnick
Dublin, California
 
Mike,

Thanks for the recommendation.

However I encountered a problem when trying to get the DLL Registered in my Win 2000 workstation.

I downloaded the nsdpgp3.zip file and extracted the separate files from the Zip file.

I then moved the nsdpgp3.dll to my C:\WINNT\SYSTEM32 directory

Next I attempted to manually Register the DLL using
regsvr32 c:\winnt\system32\nsdpgp3.dll

However I got an error message:
LoadLibrary("c:\winnt\system32\nsdpgp3.dll") failed - the specified module could not be found

Any suggestions?

Thanks,
I_Forgot_Again

 
On reading the documentation more carefully I figured it out.

It seems as though the files you suggested me to download are a support tool for PGP8. Therefore PGP8 must be installed before this DLL will Register.

It took me quite a few Google links to finally find a copy of PGP8.EXE which I could download. The new "parent" organization wants to only give a 30-day trial version of PGP9 and no longer supply PGP8.

Regardless, once I got PGP8 installed, then the above DLL did register.

I now have to figure out how to use everything.

Thanks,
I_Forgot_Again
 
Glad to help. Hope it works for you.

Mike Krausnick
Dublin, California
 
Mike,

I am back with more questions on using this DLL utility.

I have now installed PGP8 on my workstation and I have created one or more keyring(s) using the PGP8Keys utility.

I now go to try to use the DLL Utility
EncryptFile ( pubkeyring, privkeyring, infile, outfile, infiletype, outfiletype, rcptkeyid )

Where:
pubkeyring is a string giving the filename (including full path) of the PGP public keyring.
privkeyring is a string giving the filename (including full path) of the PGP private keyring

I have a LOT of questions concerning these parameters.
Such as:
* Where are the KeyRing files located on my workstation so that I can build a descriptive string?
* My PGP8Keys utility shows my KeyStings and has them all marked as Public. What do I enter as PrivKeyRing?
* Where are the KeyRing files located on my workstation so that I can build a descriptive string?
* Is the rcptkeyid a required parameter?

Obviously I have a lot of BASIC questions.
If you want to answer here, that's fine.
But with the possibility of an abundance of questions that I don't even know to ask at this point, we might want to take this "How To Make PGP Work for Dummies" discussion off line.

Let me know.

Thanks,
I_Forgot_Again
 
If you just want to encrypt with a password using PGP you can just use PGP_SDK.DLL,PGPcl.Dll from the free version; Using the NSDPGP.dll. You just need to have those two files in the same directory and register the nsdpgp.dll. Wanted something that I could distribute. Note to unencrypt the files you do need the full version.


oEncrypt = Createobject("NSDPGP")
oEncrypt.EncryptFile( 2, cMyfile, cOutFile, cFilePass)
 
No worries. Here's the skinny:

The PGP keyrings are usually located in documents and settings/username/my documents/pgp

First, create the PGP object:
Code:
oPGP = CREATEOBJECT("NSDPGP3LIB.PGP")		&& PGP Encryption engine 
cPublicPGPKeyRing  = "C:\Documents and Settings\Mike\My Documents\PGP\pubring.pkr"
cPrivatePGPKeyRing = "C:\Documents and Settings\Mike\My Documents\PGP\secring.skr"
Second, encrypt the file. Here's the sum total of my encryption code, which is mostly error trapping.

Information in variables coming in:
p_Filename - Input filename
Contact.Email - Email address of the recipient

The convention is that the PGP filename equals the entire input filename + ".PGP".

Code:
	nPGPError = 0				&& No key found for this email generates a program error, so trap it
	TRY 
		oPGP.EncryptFile(cPublicPGPKeyRing,cPrivatePGPKeyRing,;
			p_FileName,	p_FileName+".PGP",1,1,;
			oPGP.GetKeyIDFromUserID( cPublicPGPKeyRing,cPrivatePGPKeyRing,ALLTRIM(Contact.Email) )	 )
	CATCH TO oErr
		nPGPError = oErr.ErrorNo
		IF nPGPError = 1429		&& User key not found 
			MESSAGEBOX("There is no PGP key for "+ALLTRIM(Contact.Email)+".  The file "+p_FileName+" will not be sent.",0,;
						"No PGP Encryption Key",60000)
		ELSE 
		    nErrAction = MESSAGEBOX( "PGP object error:"+ BuildErrorMsg(oErr)50,"PGP Error" )
	        ENDIF 
	ENDTRY 
	p_FileName = p_FileName+".PGP"
    IF nPGPError = 0	&& Encryption was successful
    .
    . etc. 
    .


Lastly, release the PGP object.


Mike Krausnick
Dublin, California
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top