Classic ASP
Classic ASP
Set the Decryption Certificate and Private Key
See more POP3 Examples
Demonstrates the Chilkat MailMan.SetDecryptCert2 method, which explicitly specifies both the certificate and its associated private key, as separate objects, to use when decrypting S/MIME encrypted email. This example loads a .cer certificate and a PEM private key, registers both, and fetches a message Chilkat can decrypt.
Background: Credentials are not always packaged together. When the certificate is a standalone
.cer and the private key is a separate PEM (or other) file, SetDecryptCert2 takes the two objects individually. It is the two-object counterpart to SetDecryptCert, which expects a single certificate that already carries its private key (such as one loaded from a PFX).Chilkat Classic ASP Downloads
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0
' Demonstrates the MailMan.SetDecryptCert2 method, which explicitly specifies both the
' certificate and its associated private key (as separate objects) to use when decrypting
' S/MIME encrypted email.
set mailman = Server.CreateObject("Chilkat.MailMan")
' Configure the POP3 server connection.
mailman.MailHost = "pop.example.com"
mailman.MailPort = 995
mailman.PopSsl = 1
mailman.PopUsername = "user@example.com"
mailman.PopPassword = "myPassword"
' Load the certificate (public) and the matching private key from separate files.
set cert = Server.CreateObject("Chilkat.Cert")
success = cert.LoadFromFile("qa_data/certs/recipient.cer")
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( cert.LastErrorText) & "</pre>"
Response.End
End If
set privKey = Server.CreateObject("Chilkat.PrivateKey")
success = privKey.LoadPemFile("qa_data/certs/recipient_privkey.pem")
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( privKey.LastErrorText) & "</pre>"
Response.End
End If
' Specify the certificate and private key to use when decrypting downloaded email.
success = mailman.SetDecryptCert2(cert,privKey)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( mailman.LastErrorText) & "</pre>"
Response.End
End If
' Fetch a message; if it is encrypted, Chilkat decrypts it using the certificate and key.
set email = Server.CreateObject("Chilkat.Email")
success = mailman.FetchOne(0,0,1,email)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( mailman.LastErrorText) & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( "Decrypted = " & email.Decrypted) & "</pre>"
' Note: Paths such as "qa_data/..." are relative local filesystem paths,
' relative to the current working directory of the running application.
' Note: Explicitly connecting/authenticating is optional. Chilkat MailMan automatically
' connects and authenticates -- using the property settings above -- whenever a server
' operation requires it. Calling the explicit connect/authenticate methods can still be
' helpful to determine whether a failure occurs while connecting or while authenticating.
%>
</body>
</html>