How-to send PGP encrypted emails (Pretty Good Privacy)
This is something I hacked a while back for some PGP encrypted emails that I needed to process. Its working nicely for me. I know its ugly but its damn unique! I haven't seen anything out there that does what this code does. I hope you can use it somehow as I'm sure I wasn't the only one looking for an easy way to decrypt/encrypt PGP.
This is the following example uses the DOS based PGP encryption/decryption program
availble from http://www.pgpi.org/ Configure the software with your PGP key by following the directions in the included files.
A self made component or a third part component like ASPExec from
http://www.serverobjects.com can be used to execute the PGP decryption
execututable.
An example VB component to do this task would contain the following code in
a Class Module.
Dim sTest, i As Integer
Dim sCommand As String
Dim sPGPTXT As String
Public Property Let Command(temp As Variant)
sCommand = temp
End Property
Public Property Get Command() As Variant
Command = sCommand
End Property
Public Property Let PGPTXT(temp As Variant)
sPGPTXT = temp
End Property
Public Property Get PGPTXT() As Variant
PGPTXT = sPGPTXT
End Property
Public Sub PGPDecrypt()
sTest = Shell(sCommand, vbMinimizedNoFocus)
sTest = ""
i = 0
Do While Not sTest = "Exit"
i = i + 1
If i > 30 Then
sTest = "Exit"
End If
If GetFileAttributes(sPGPTXT) <> -1 Then sTest = "Exit"
Sleep (500)
Loop
End Sub
To call this component from within ASP:
Set oFS = CreateObject("Scripting.FileSystemObject")
Response.Write "Decyrypting"
Set oPGP = Server.CreateObject("NWCRPGP.PGP")
oPGP.Command = "C:\inetpub\wwwroot\pgp\pgp.bat"
oPGP.PGPTXT = "C:\Inetpub\wwwroot\pgp\ASP.TXT"
Response.Write ".."
If oFS.FileExists("C:\Inetpub\wwwroot\pgp\asp.txt") Then
Set oFSTemp = oFS.GetFile("C:\Inetpub\wwwroot\pgp\asp.txt")
oFSTemp.Delete
Set oFSTemp = Nothing
Response.Write "."
End If
If oFS.FileExists("C:\Inetpub\wwwroot\pgp\asp.pgp") Then
Set oFSTemp = oFS.GetFile("C:\Inetpub\wwwroot\pgp\asp.pgp")
oFSTemp.Delete
Set oFSTemp = Nothing
Response.Write "."
End If
Set oFSTemp = oFS.CreateTextFile("C:\Inetpub\wwwroot\pgp\asp.pgp", True)
Response.Write ".."
oFSTemp.Write sTemp
oFSTemp.Close
Set oFSTemp = Nothing
Response.Write ".."
oPGP.PGPDecrypt
Response.Write "...."
Set oFSTemp = oFS.OpenTextFile("C:\Inetpub\wwwroot\pgp\ASP.TXT")
Response.Write oFSTemp.ReadAll
oFSTemp.Close
Set oFSTemp = Nothing
Set oFSTemp = oFS.GetFile("C:\Inetpub\wwwroot\pgp\asp.txt")
oFSTemp.Delete
Set oFSTemp = Nothing
Set oFSTemp = oFS.GetFile("C:\Inetpub\wwwroot\pgp\asp.pgp")
oFSTemp.Delete
Set oFSTemp = Nothing
Set oFS = Nothing
Set oPGP = Nothing
Contained in the pgp.bat file is:
c: CD \inetpub\wwwroot\pgp
pgp -v -o asp.txt -z password asp.pgp
This code is in no way in a condition for production use.
Things to think about:
Decrypting to a file is insecure because your unencrypted message will be
saved, even if temporarily, to the HD which could allow access to it.
Sending the PGP encrypted message directly and receiving to/from the program
would be much more secure. If multiple instances of this ran they would conflict since its using the
same file names.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More ASP Code Articles
More By aspfree
developerWorks - FREE Tools! |
<a href="http://zeus.developershed.com/shonuff.php?blackbird=3853&zoneid=442&source=&dest=http%3A%2F%2Fwww.ibm.com%2Fdeveloperworks%2Fspaces%2Fjazz%3FS_TACT%3D105AGY31%26S_CMP%3DDEVSHED&ismap="><img src="http://images.devshed.com/corp/img/news/jazz01.gif" alt="developerWorks Jazz space" align="left"></a>You've heard the buzz about Jazz... want to know more about it from a developer's perspective? Check out the Jazz space on developerWorks. This space is an up-to-date resource for developers, including technical information about Jazz and products built on Jazz, like Rational Team Concert Express. The Jazz space includes content from a wide variety of sources, including links, feeds, and comments from experts. FREE! Go There Now!
|
|
|
|
WebSphere Process Server delivers a unique integration framework that simplifies existing IT resources. Often, as IT assets grow to support business demand, so too does their complexity and manageability. In this webcast, we’ll discuss how WebSphere Process Server helps deliver an SOA infrastructure that provides a common model to orchestrate, mediate, connect, map, and execute the underlying IT functions. Discover how WebSphere Process Server simplifies integration of business processes by leveraging existing IT assets as reusable services without the complexities of traditional integration methodologies. FREE! Go There Now!
|
|
|
|
Manage, govern, and share services across your organization by using WebSphere Service Registry and Repository. Follow the hands-on exercises to learn how to navigate the Web interface to publish, find, reuse, and update services. FREE! Go There Now!
|
|
|
|
IBM Enterprise Modernization solutions help organizations evolve core IT systems towards modern architectures and technologies—reducing the burden of maintenance and freeing up resources to develop new business requirements and capabilities. With the IBM Enterprise Modernization Sandbox for System z you can evaluate IBM Enterprise Modernization solutions focused on five key areas: Assets, Architectures, Skills, Processes and Infrastructures, and Investment. Each solution is based upon real customer experiences and offers a proven path to get you started with your modernization projects. FREE! Go There Now!
|
|
|
|
Analysts, architects, and developers who have existing COBOL or PL/I skills and want to extend those skills to deploy new workloads on the mainframe can use the IBM Enterprise Modernization Sandbox for System z to find hands-on walkthroughs of common real world scenarios. The scenarios provide examples of how to rapidly design, create, assemble, test, and deploy high-quality Web, Web services, portal, and SOA applications for IBM CICS, IBM IMS, and IBM WebSphere Application Server. FREE! Go There Now!
|
|
|
|
Secure your Web applications with IBM Rational AppScan Standard Edition V7.7, previously known as Watchfire AppScan. This Web application security testing tool automates vulnerability assessments and scans and tests for common Web application vulnerabilities. Visit IBM developerWorks to download a free trial of IBM Rational AppScan Standard Edition V7.7. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on December 11 at 1:00 pm ET to get tips on building your own plugins with Rational Method Composer. Get your questions answered! FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on December 6 at 1:00 pm ET to participate in an agile application development discussion and get your questions answered on using IBM Rational Method Composer in a distributed environment.Get your questions answered! FREE! Go There Now!
|
|
|
|
Learn the basics of the IBM Customer Information Control System (CICS). With a hands-on exercise, learn how to get your first CICS application up and running on your desktop using TXSeries V6.1 for Windows. The tutorial shows you how to download and install a free trial version of TXSeries V6.1. FREE! Go There Now!
|
|
|
|
In this webcast, IBM Rational will discuss the importance of Web application security and will share techniques and best practices to introduce application security testing into current QA processes including: understanding common security vulnerabilities and techniques to integrate security testing with defect tracking and remediation systems in an effort to safeguard sensitive online information. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |