Mail.Decrypt Method


Decrypts the encrypted email by digital certificate. This method is obsoleted, use DecryptMessage method instead.

[Visual Basic]
Public Function Decrypt( _
    cert As Certitifcate _
) As Mail
[C#]
public Mail Decrypt(
    Certitifcate cert
);
[C++]
public: Mail^ Decrypt(
    Certitifcate * cert
);
[JScript]
public function Decrypt( 
    cert : Certitifcate
) : Mail;

Parameters

cert
The certificate to decrypt the email, if set null ( Nothing in Visual Basic), this method searches certificate from current user certificate storage automatically.

Return Value

The decrypted Mail instance.

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 oMail As New Mail("TryIt")
oMail.Load("c:\test.eml, False)

If (oMail.IsEncrypted) Then
    Try
        ' this email is encrypted, we decrypt it by user default certificate.
        ' you can also use specified certificate like this
        ' Dim oCert As New Certificate()
        ' oCert.Load("c:\test.pfx", "pfxpassword", Certificate.CertificateKeyLocation.CRYPT_USER_KEYSET)
        ' oMail = oMail.Decrypt(oCert)
        oMail = oMail.Decrypt(Nothing)
    Catch ep As Exception
        MessageBox.Show(ep.Message)
    End Try
End If

If (oMail.IsSigned) Then
    Try
        ' this email is digital signed.
        Dim cert As EAGetMail.Certificate = oMail.VerifySignature()
        MessageBox.Show("This email contains a valid digital signature.")
        ' you can add the certificate to your certificate storage like this
        ' cert.AddToStore(Certificate.CertificateStoreLocation.CERT_SYSTEM_STORE_CURRENT_USER,"addressbook");
        ' 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 oMail = new Mail("TryIt"); oMail.Load("c:\\test.eml", false); if(oMail.IsEncrypted) { try { // this email is encrypted, we decrypt it by user default certificate. // you can also use specified certificate like this // Certificate oCert = new Certificate(); // oCert.Load("c:\test.pfx", "pfxpassword", Certificate.CertificateKeyLocation.CRYPT_USER_KEYSET) // oMail = oMail.Decrypt(oCert); oMail = oMail.Decrypt(null); } catch(Exception ep) { MessageBox.Show(ep.Message); } } if(oMail.IsSigned) { try { // this email is digital signed. EAGetMail.Certificate cert = oMail.VerifySignature(); MessageBox.Show("This email contains a valid digital signature."); // you can add the certificate to your certificate storage like this // cert.AddToStore(Certificate.CertificateStoreLocation.CERT_SYSTEM_STORE_CURRENT_USER, // "addressbook"); // then you can use send the encrypted email back to this sender. } catch(Exception ep) { MessageBox.Show(ep.Message); } }

Remarks

To learn more about email digital signature and encryption, please refer to Digital Signature and E-mail Encryption/Decryption section.

See Also

Mail.IsSigned Property
Mail.VerifySignature Method
Mail.IsEncrypted Property

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