Verifies the digital signature of the email.
[Visual Basic] Public Function VerifyMessageSignature( _ ) As X509Certificate2
[C#] public X509Certificate2 VerifyMessageSignature( );
[C++] public: X509Certificate2^ VerifyMessageSignature( );
[JScript] public function VerifyMessageSignature( ) : X509Certificate2;
Return Value
Example
[Visual Basic, C#, 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.
[VB - Verify and Decrypt Email]
Dim mail As Mail = New Mail("TryIt")
mail.Load("c:\test.eml", False)
If mail.IsEncrypted Then
Try
' this email is encrypted, we decrypt it by user default certificate.
' you can also use specified certificate like this
' Dim decryptCert As New X509Certificate2("D:\mycert\test.pfx",
' "nosecret",
' X509KeyStorageFlags.Exportable Or X509KeyStorageFlags.UserKeySet)
' mail.DecryptMessage(decryptCert)
mail.DecryptMessage(Nothing)
Catch ep As Exception
MessageBox.Show(ep.Message)
End Try
End If
If mail.IsSigned Then
Try
Dim signerCert As X509Certificate2 = mail.VerifyMessageSignature()
MessageBox.Show("This email contains a valid digital signature.")
' You can add the certificate to your certificate storage like this
' Dim store As New X509Store("My", StoreLocation.CurrentUser)
' store.Open(OpenFlags.ReadWrite)
' store.Add(signerCert)
' store.Close()
' then you can use send the encrypted email back to this sender.
Catch ep As Exception
MessageBox.Show(ep.Message)
End Try
End If
[C# - Verify and Decrypt Email]
Mail mail = new Mail("TryIt");
mail.Load("c:\\test.eml", false);
if (mail.IsEncrypted)
{
try
{
// this email is encrypted, we decrypt it by user default certificate.
// you can also use specified certificate like this
/* X509Certificate2 decryptCert = new X509Certificate2("D:\\mycert\\test.pfx",
"nosecret",
X509KeyStorageFlags.Exportable | X509KeyStorageFlags.UserKeySet);
mail.DecryptMessage(decryptCert);
*/
mail.DecryptMessage(null);
}
catch (Exception ep)
{
MessageBox.Show(ep.Message);
}
}
if (mail.IsSigned)
{
try
{
// This email is digital signed.
X509Certificate2 signerCert = mail.VerifyMessageSignature();
MessageBox.Show("This email contains a valid digital signature.");
// You can add the certificate to your certificate storage like this
/*
X509Store store = new X509Store("My", StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadWrite);
store.Add(signerCert);
store.Close();
*/
// then you can use send the encrypted email back to this sender.
}
catch (Exception ep)
{
MessageBox.Show(ep.Message);
}
}
Remarks
See Also
Mail.IsEncrypted Property
Mail.IsSigned Property
Mail.Decrypt Method
Online Tutorials
Verify Digital Signature and Decrypt Email in C# - Tutorial
Verify Digital Signature and Decrypt Email in VB.NET - Tutorial
Verify Digital Signature and Decrypt Email in C++/CLI - Tutorial