NSDPGP.DLL v3.20 COM Interface to PGP 6.5.2 Freeware. Freely distributable. Copyright (c) 1999, Gerard R Thomas. email: http://community.wow.net/grt/nsdpgp.html This program is "freeware" and may be used and copied, without fee or obligation, for private or commercial use. If you do use it for commercial purposes, you may wish to contribute to the further development. You can send an online gift certificate from http://www.amazon.com to Gerard R Thomas grt@wow.net See the license.txt for license information. Installation: Please uninstall previous versions of NSDPGP.DLL before installing version 3.2. The nsdpgp.zip file contains these files: file_id.diz (package information) readme.txt (program information) license.txt (license) nsdpgp.dll (COM Interface DLL for PGP version 6.5.2) nsdpgp.dll.sig (PGP signature) Copy the nsdpgp.dll file to the \System32 directory (Windows NT 4.0) or the \System directory (Windows 98/95). Register the file by typing into the Start | Run "REGSVR32 NSDPGP.DLL" If using this DLL with IIS4 or PWS4, see the note below on the modifications required for proper keyring use by PGP. Uninstall: Unregister the file by typing into the Start | Run "REGSVR32 /U NSDPGP.DLL" Delete the nsdpgp.dll file. Operation: NSDPGP.DLL is a COM In-Process Automation Server. Its interface provides wiping methods, conventional (128 bit IDEA, CAST5, 3DES) file encryption and decryption methods and public key (RSA, DH/DSS) file encryption, encryption+signing, decryption+verification, signing (MD5, SHA1, RIPEMD160) and verification methods to clients such as ASP, the Windows Scripting Host, Visual Basic, MS Office VBA, Java, Delphi, Visual C++ etc. I have tested it with PGP 6.5.2 on Windows NT 4.0 Server and Workstation (Service Pack 6) using ASP (IIS4 / PWS4), VB6, VC6 and WSH. The ten methods are: EncryptFile( cipher, infile, outfile, password ) DecryptFile( infile, outfile, password ) SignFile( hash, signkeyid, infile, outfile, password ) VerifyFile( siginfofile, infile ) WipeFile( infile ) EncryptFileEx( rcptkeyid, signkeyid, infile, outfile, password ) DecryptFileEx( siginfofile, infile, outfile, password ) SignFileEx( hash, signkeyid, infile, sigfile, password ) VerifyFileEx( siginfofile, infile, sigfile ) WipeFileEx( infile ) parameters: cipher is an integer that indicates the desired conventional cipher algorithm. Valid values are 1 (for IDEA), 2 (for CAST5) and 3 (for 3DES). hash is an integer that indicates the desired hashing algorithm. Valid values are 1 (for MD5), 2 (for SHA1) and 3 (for RIPEMD160). infile and outfile are strings giving the filenames (including full path) of the input and output files. password is a string giving the conventional password or keyring passphrase. sigfile is a string giving the filename (including full path) of the detached signature file. rcptkeyid and signkeyid are strings giving the KeyIDs of the recipient and signing keys. The signkeyid parameter to EncryptFileEx() may be "NOSIGN". This will cause the output file to be encrypted but not signed. siginfofile is a string giving the filename (including full path) of the file into which the signature verification information will be written. This information will be preceeded by one of the following signature status strings: SIGSTS_NOTSIGNED SIGSTS_VERIFIED SIGSTS_NOTVERIFIED SIGSTS_BADSIG SIGSTS_VERIFIED_UNTRUSTED Usage examples: (1) using the Windows Scripting Host and JScript pgpobj = WScript.CreateObject("NSDPGP"); pgpobj.EncryptFile(2,"D:\\Reports\\JUL99.DOC","D:\\Reports\\JUL99.ENC","secret"); pgpobj.WipeFile("D:\\Reports\\SCRATCHPAD.XLS"); pgpobj.DecryptFileEx("D:\\Temp\\siginfo.txt","D:\\Reports\\OCT99.PGP","D:\\Reports\\OCT99.MDB","secret"); pgpobj.EncryptFileEx("0xFF7177A2","0x9DBCDE7D","D:\\Photos\\Portrait.JPEG","D:\\Temp\\Portrait.PGP","secret"); pgpobj.VerifyFileEx("c:\\temp\\siginfo.txt","c:\\winnt\\nav.exe","c:\\winnt\\nav.exe.sig"); pgpobj.SignFileEx(3,"0xFF7155A2","c:\\upload\\photos.zip","c:\\upload\\photos.zip.sig","secret phrase"); pgpobj.EncryptFileEx("0xFF7177A2","nosign","D:\\Photos\\Photo.JPEG","D:\\Temp\\photo.PGP",""); (2) using .ASP on IIS4 or PWS4 NSDPGP Test <% set pgpobj = server.createobject("NSDPGP") if isobject(pgpobj) then pgpobj.EncryptFileEx "0xFF7155A2","0x9DBCDE7D","C:\\temp\\test.txt","C:\\temp\\test.pgp","passphrase here" else response.write "Error creating object" end if set pgpobj = nothing %>
done (3) using Visual Basic (a) choose Standard EXE project (b) choose Project | References and check the "PGP COM Interface" checkbox. (c) place a commandbutton control on Form1 (d) enter the following code Private Sub Command1_Click() Dim myRef as new NSDPGP.NSDPGP myRef.DecryptFile "D:\Reports\JUL99.DOC", "D:\Reports\Scratch.DOC", "testing" myRef.EncryptFileEx "0xFF7155A2", "0x9DBCDE7D", "D:\temp\info.txt", "d:\temp\cryptedinfo.txt", "secret" End Sub (e) run the code and click on the button (4) Using Inprise Delphi (The file NSDPGP_TLB.pas is the file created through the Import Type Library option in Delphi) uses NSDPGP_TLB,ComObj; procedure TForm1.EncryptFileBtnClick(Sender: TObject); Var VarW: Variant; infile,outfile : string; password : Widestring; begin infile := 'C:\Test.txt'; outfile := 'C:\Temp.txt'; Password := 'Rome is on fire'; VarW := CreateOleObject('NSDPGP'); VarW.EncryptFile(3,infile,outfile,password); end; (5) using Visual C++ #import "c:\winnt\system32\nsdpgp.dll" no_namespace void main() { CoInitialize(NULL); INSDPGPPtr myRef(__uuidof(NSDPGP)); myRef->WipeFile("d:\\temp\\readme.txt"); myRef = NULL; CoUninitialize(); } Note: PGP versions 6.5.2 or 6.5.1 must be installed on the system for this interface to work. It will not work with other versions of PGP. It will not work with the command line version of PGP. It requires the file PGP_SDK.DLL from the full GUI version. It is not a standalone encryptor but rather a thin COM wrapper to PGP. The actual cryptographic operations are performed by PGP itself. The DLL simply passes the data (file names etc) to PGP_SDK.DLL for processing. Note: Using this interface with .ASP on IIS4 or PWS4 requires that keyrings be available. IIS runs as an NT service and any DLL hosted by it is run by the system, not the currently logged on user or the administrator. Typically crypto functions will fail with PGP reporting that no keys were found even though valid rings/keys are present (belonging to current user or administrator). This is fixed by providing default user rings. In the directory \WINNT\Profiles\\Application Data\PGP you will find files like PGPsdk.dat, PGPgroup.pgr, PGPMacBinaryMappings.txt, PGPclient.dat. Copy these files to the directory \WINNT\Profiles\Default User\Application Data\PGP This will allow use of your keyrings by the system and IIS4. This assumes the IIS user id (IUSR_computername) is set for the "default user" profile. If IIS is set to use another profile, add the PGP subdirectory to that profile. The NT rights also need to be updated for that PGP subdirectory. Make sure you allow read access for the IIS user ID under the profile/statistics server/application/pgp directory. Note: The PGP signature may be used to verify the integrity of the executable. The executable is signed with my PGP DSS key. [4096/1024 bit DH/DSS Key ID: 0xFF7155A2 Key fingerprint: 61DF 0468 0570 4615 8FF5 7530 5B3C 2165 FF71 55A2] 1999 11 20 Gerard R Thomas Port of Spain Trinidad and Tobago