Verifies the digital signature of the email.
[Visual Basic 6.0] Public Function VerifySignature( _ ) As Certitifcate
[Visual C++] public: HRESULT VerifySignature( ICertitifcate** pVal );
Return Value
Example
[Visual Basic 6.0, VBScript, Visual C++] The following example demonstrates how to verify signed email and decrypt encrypted email with EAGetMail POP3 & IMAP4 Component. To get the full samples of EAGetMail, please refer to Samples section.
[Visual Basic 6.0]
Const CRYPT_MACHINE_KEYSET = 32
Const CRYPT_USER_KEYSET = 4096
Const CERT_SYSTEM_STORE_CURRENT_USER = 65536
Const CERT_SYSTEM_STORE_LOCAL_MACHINE = 131072
On Error Resume Next
Dim oMail As New EAGetMailObjLib.Mail
oMail.LicenseCode = "TryIt"
oMail.LoadFile "c:\test.eml", False
If Err.Number <> 0 Then
MsgBox Err.Description
Exit Sub
End If
If (oMail.IsEncrypted) Then
' this email is encrypted, we decrypt it by user default certificate.
' you can also use specified certificate like this
' Dim oCert As New EAGetMailObjLib.Certificate
' oCert.LoadFromFile "c:\test.pfx", "pfxpassword", CRYPT_USER_KEYSET
' Set oMail = oMail.Decrypt( oCert )
Set oMail = oMail.Decrypt(Nothing)
If Err.Number <> 0 Then
MsgBox Err.Description
Exit Sub
End If
End If
If (oMail.IsSigned) Then
'this email is digital signed.
Dim oCert As EAGetMailObjLib.Certificate
Set oCert = oMail.VerifySignature()
If Err.Number <> 0 Then
MsgBox Err.Description
Exit Sub
End If
MsgBox "This email contains a valid digital signature."
'you can add the certificate to your certificate storage like this
'oCert.AddToStore CERT_SYSTEM_STORE_CURRENT_USER,"addressbook"
'then you can use send the encrypted email back to this sender.
End If
[VBScript]
Const CRYPT_MACHINE_KEYSET = 32
Const CRYPT_USER_KEYSET = 4096
Const CERT_SYSTEM_STORE_CURRENT_USER = 65536
Const CERT_SYSTEM_STORE_LOCAL_MACHINE = 131072
On Error Resume Next
Dim oMail
Set oMail = CreateObject("EAGetMailObj.Mail")
oMail.LicenseCode = "TryIt"
oMail.LoadFile "c:\test.eml", False
If Err.Number <> 0 Then
MsgBox Err.Description
Exit Sub
End If
If (oMail.IsEncrypted) Then
' this email is encrypted, we decrypt it by user default certificate.
' you can also use specified certificate like this
' Dim oCert
' Set oCert = CreateObject("EAGetMailObj.Certificate")
' oCert.LoadFromFile "c:\test.pfx", "pfxpassword", CRYPT_USER_KEYSET
' Set oMail = oMail.Decrypt( oCert )
Set oMail = oMail.Decrypt(Nothing)
If Err.Number <> 0 Then
MsgBox Err.Description
Exit Sub
End If
End If
If (oMail.IsSigned) Then
'this email is digital signed.
Dim oCert
Set oCert = oMail.VerifySignature()
If Err.Number <> 0 Then
MsgBox Err.Description
Exit Sub
End If
MsgBox "This email contains a valid digital signature."
'you can add the certificate to your certificate storage like this
'oCert.AddToStore CERT_SYSTEM_STORE_CURRENT_USER,"addressbook"
'then you can use send the encrypted email back to this sender.
End If
[Visual C++]
#include "eagetmailobj.tlh"
using namespace EAGetMailObjLib;
::CoInitialize( NULL );
try
{
IMailPtr oMail = NULL;
oMail.CreateInstance("EAGetMailObj.Mail");
oMail->LicenseCode = _T("TryIt");
oMail->LoadFile( _T("d:\\test.eml"), VARIANT_FALSE );
if( oMail->IsEncrypted == VARIANT_TRUE )
{
//this email is encrypted, we decrypt it by user default certificate.
// you can also use specified certificate like this
//ICertificatePtr oCert;
//oCert.CreateInstance("EAGetMailObj.Certificate");
//oCert->LoadFromFile( _T("c:\\test.pfx"), _T("pfxpassword"), CRYPT_USER_KEYSET );
//oMail = oMail->Decrypt( oCert);
oMail = oMail->Decrypt( NULL );
}
if( oMail->IsSigned == VARIANT_TRUE )
{
ICertificatePtr oCert = oMail->VerifySignature();
MessageBox( NULL, _T("This email contains a valid digital signature."), NULL, MB_OK );
//you can add the certificate to your certificate storage like this
//oCert->AddToStore( CERT_SYSTEM_STORE_CURRENT_USER, _T("addressbook"));
// then you can use send the encrypted email back to this sender.
}
}
catch( _com_error &ep )
{
MessageBox( NULL, (TCHAR*)ep.Description(), NULL, MB_OK );
}
::CoUninitialize();
Remarks