Sample code for 30+ languages & platforms
Classic ASP Requires Chilkat v11.0.0+

Decrypt an S/MIME email and verify its signature

See more Email Object Examples

Register the recipient’s PFX before opening signed-encrypted.eml. This workflow expects both encryption and a signature, so it checks both layers before reading the message. Cryptographic signature validity is one input to a signer-trust decision.

Chilkat Classic ASP Downloads

Classic ASP
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0

'  Assumes Chilkat is unlocked. See Global Unlock Sample.

set email = Server.CreateObject("Chilkat.Email")
success = email.AddPfxSourceFile("recipient.pfx","RECIPIENT_PASSWORD")
If (success <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( email.LastErrorText) & "</pre>"
    Response.End
End If

success = email.LoadEml("signed-encrypted.eml")
If (success <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( email.LastErrorText) & "</pre>"
    Response.End
End If

If ((email.ReceivedEncrypted <> 1) Or (email.Decrypted <> 1)) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Expected a successfully decrypted S/MIME envelope.") & "</pre>"
    Response.End
End If

If ((email.ReceivedSigned <> 1) Or (email.SignaturesValid <> 1)) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Expected a valid signature inside the envelope.") & "</pre>"
    Response.End
End If

'  This message has one signer. Examine its certificate after verification.
set signer = Server.CreateObject("Chilkat.Cert")
success = email.LastSignerCert(0,signer)
If (success <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( email.LastErrorText) & "</pre>"
    Response.End
End If

Response.Write "<pre>" & Server.HTMLEncode( "Signer certificate: " & signer.SubjectDN) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "Recovered subject: " & email.Subject) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "Recovered attachments: " & email.NumAttachments) & "</pre>"

%>
</body>
</html>