Click to visit Hosting Systems
Hosting Systems - Serving your business - for all your windows hosting requirements.

ENCRYPTION USING PGP URL: http://community.wow.net/grt/nsdpgp.html

The Object has eighteen methods. Each returns a standard COM HRESULT (either S_OK or E_FAIL) with error information provided via the COM interface ISupportErrorInfo. This error interface is automatically used by scripting clients such as ASP and WSH and they transparently return the error information to the user. The error information can also accessed with a try..catch statement (JScript/WSH). With Visual Basic, the built in error object Err has to be used (with an error handler). With Visual C++, the _com_error type can be used (with an exception handler). See the example code for more information on this.

Many methods take a KeyID as input. A convenience method is also provided to give the KeyID of a key from a supplied UserID (the email address).

The File methods output data in standard PGP ASCII Armor format.

The String methods do NOT use ASCII armor. Instead the output is the textual hexadecimal representation of the actual PGP binary output data and thus non-portable (to a system without the NSDPGP2.DLL) unless you first reconstruct the PGP binary data from the text string.

(1) ConvEncryptFile ( cipher, infile, outfile, passphrase )

(2) EncryptFile ( rcptkeyid, infile, outfile, pubkeyring, privkeyring )

(3) EncryptAndSignFile ( alg, rcptkeyid, signkeyid, passphrase, infile, outfile, pubkeyring, privkeyring )

(4) DecryptFile( siginfofile, infile, outfile, passphrase, pubkeyring, privkeyring )

(5) ClearSignFile( alg, signkeyid, passphrase, infile, outfile, pubkeyring, privkeyring )

(6) OpaqueSignFile( alg, signkeyid, passphrase, infile, outfile, pubkeyring, privkeyring )

(7) SignFile( alg, signkeyid, passphrase, infile, sigfile, pubkeyring, privkeyring )

(8) VerifySignedFile( siginfofile, infile, pubkeyring, privkeyring )

(9) VerifyFile( siginfofile, infile, sigfile, pubkeyring, privkeyring )

(10) WipeFile( infile )

(11) outputstring = ConvEncryptString( cipher, passphrase, inputstring )

(12) outputstring = EncryptString( pubkeyring, privkeyring, rcptkeyid, inputstring )

(13) outputstring = DecryptString( pubkeyring, privkeyring, passphrase, inputstring )

(14) keyid = GetKeyIDFromUserID( pubkeyring, privkeyring, userid )

(15) GenerateKey( keyalg, bits, name, passphrase, pubkeyring, privkeyring )

(16) ImportKeyFromFile( infile, pubkeyring, privkeyring )

(17) ImportKeyFromKeyServer( userid, keyserver, pubkeyring, privkeyring )

(18) ExportKeyToFile( keyid, outfile, pubkeyring, privkeyring )

parameters:

(a) cipher is an integer that indicates the desired PGP conventional cipher algorithm. Valid values are 0 - 4
0 - CAST5
1 - IDEA
2 - TripleDES
3 - AES
4 - Twofish
Clients that can access the built in typelib of the DLL can use the enum variable name instead of the integer value (e.g. Cast5 rather than 0, Twofish rather than 4).

(b) infile is a string giving the filename (including full path) of the input file. UNC paths may be used.

(c) outfile is a string giving the filename (including full path) of the output file. UNC paths may be used. Note that outfile and infile should NOT be the same. This will work for small files but fails with larger ones (with PGP deleting the file).

(d) passphrase is a string giving the conventional passphrase or the PGP keyring passphrase.

(e) rcpkeyid is a string giving the KeyID (e.g. "0x9DBCDE7D") of the recipient's public key. Note that if the public key has an associated ADK, the ADK will be ignored.

(f) pubkeyring is a string giving the filename (including full path) of the PGP public keyring. UNC paths may be used.

(g) privkeyring is a string giving the filename (including full path) of the PGP private keyring. UNC paths may be used.

(h) alg is an integer that indicates the desired PGP hash algorithm. Valid values are 0 - 2
0 - MD5
1 - SHA1
2 - RIPEMD160
Clients that can access the built in typelib of the DLL can use the enum variable name instead of the integer value (e.g. MD5 rather than 0).

(i) signkeyid is a string giving the KeyID (e.g. "0x9DBCDE7D") of the signing key.

(j) siginfofile is a string giving the filename (including full path) of the file into which the signature status information should be written. UNC paths may be used. The status information will include one of the following signature status strings: SIGSTS_NOTSIGNED
SIGSTS_VERIFIED
SIGSTS_NOTVERIFIED
SIGSTS_BADSIG
SIGSTS_VERIFIED_UNTRUSTED

(k) sigfile is a string giving the filename (including full path) of the detached signature file. UNC paths may be used.

(l) inputstring is a string (4 KB suggested maximum) with the input data to be processed.

(m) outputstring is a string into which the output data is written. For the EncryptString and ConvEncryptString methods, the output is the textual hexadecimal representation of the actual PGP binary output data. The input to DecryptString MUST also be in this format. Note that the output string is NOT in PGP ASCII Armored format (e.g. "--Begin PGP Message") and thus non-portable (to a system without the NSDPGP2.DLL) unless you first reconstruct the PGP binary data from the text string.

(n) keyid is a string giving the KeyID (e.g. "0x9DBCDE7D") of the PGP key.

(o) userid is a string giving the email address (e.g. "grt@wow.net") of the PGP key.

(p) keyalg is is an integer that indicates the desired PGP key pair type to be created. Valid values are 0 - 1
0 - RSA
1 - DH_DSS
Clients that can access the built in typelib of the DLL can use the enum variable name instead of the integer value (e.g. DH_DSS rather than 1).

(q) bits is an integer giving the size of the key pair to be created. Valid range is 1024 to 4096 bits

(r) name is a string giving the name and email address (e.g. "John Doe ") of the key pair to be created.

(s) keyserver is a string giving the name of a keyserver (e.g. "keyserver.pgp.com") from which the key will be downloaded.

EXAMPLE CODE: using .ASP on IIS5

<html>
<head>
<title> test.asp </title>
</head>
<body>
<%
dim alg
dim instr
dim outstr
dim pass
dim decstr
dim pubring
dim privring
dim rkeyid

set pgpobj = server.createobject("Nsdpgp2Lib.PGP")

alg = 1
instr = "Test of the PGP COM Object"
pass = "my secret phrase"
pubring = "c:\\tmp\\pubring.pkr"
privring = "c:\\tmp\\secring.skr"

if isobject(pgpobj) then
response.write("conventional string test <BR>")
response.write(instr & "<BR>")
outstr = pgpobj.ConvEncryptString(alg,pass,instr)
response.write(outstr & "<BR>")
decstr = pgpobj.DecryptString(pubring,privring, pass, outstr)
response.write(decstr & "<BR>")
response.write("file test <BR>")
rkeyid = pgpobj.GetKeyIDFromUserID( pubring, privring, "grt@wow.net");
pgpobj.EncryptAndSignFile 1, rkeyid, "0x9DBCDE7D","my secret", "c:\\my documents\\thesis.doc", "c:\\my documents\\thesis.doc.pgp", "c:\\pgp rings\\pubring.pkr", "c:\\pgp rings\secring.skr"

else
response.write("Error creating object")
end if

set pgpobj = nothing
%>
<br>
all done
</body>
</html>