VBScript Requires Chilkat v11.8.0+
VBScript
Decrypt an S/MIME email and verify its signature
See more Email Object Examples
Register the recipient’s certificate and private key (from a PEM file) 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 VBScript Downloads
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)
success = 0
' Assumes Chilkat is unlocked. See Global Unlock Sample.
set email = CreateObject("Chilkat.Email")
' The recipient's certificate and private key are in a PEM file. The 2nd argument of LoadPemFile
' is the password of the private key.
set pem = CreateObject("Chilkat.Pem")
success = pem.LoadPemFile("recipient.pem","RECIPIENT_PASSWORD")
If (success <> 1) Then
outFile.WriteLine(pem.LastErrorText)
WScript.Quit
End If
success = email.AddPemSource(pem)
If (success <> 1) Then
outFile.WriteLine(email.LastErrorText)
WScript.Quit
End If
success = email.LoadEml("signed-encrypted.eml")
If (success <> 1) Then
outFile.WriteLine(email.LastErrorText)
WScript.Quit
End If
If ((email.ReceivedEncrypted <> 1) Or (email.Decrypted <> 1)) Then
outFile.WriteLine("Expected a successfully decrypted S/MIME envelope.")
WScript.Quit
End If
If ((email.ReceivedSigned <> 1) Or (email.SignaturesValid <> 1)) Then
outFile.WriteLine("Expected a valid signature inside the envelope.")
WScript.Quit
End If
' This message has one signer. Examine its certificate after verification.
set signer = CreateObject("Chilkat.Cert")
success = email.LastSignerCert(0,signer)
If (success <> 1) Then
outFile.WriteLine(email.LastErrorText)
WScript.Quit
End If
outFile.WriteLine("Signer certificate: " & signer.SubjectDN)
outFile.WriteLine("Recovered subject: " & email.Subject)
outFile.WriteLine("Recovered attachments: " & email.NumAttachments)
outFile.Close