EncryptionAlgorithmType Enumeration


Provides enumered values for e-mail encryption algorithm. RSAES-OAEP algorithm is recommended.

[Visual Basic]
Public Enum EncryptionAlgorithmType
[C#]
public enum EncryptionAlgorithmType
[C++]
__value public enum EncryptionAlgorithmType
[JScript]
public enum EncryptionAlgorithmType

Members

Members name Description
ENCRYPTION_ALGORITHM_RC2 Uses RSA RC2 encryption.
ENCRYPTION_ALGORITHM_RC4 Uses RSA RC4 encryption.
ENCRYPTION_ALGORITHM_DES Uses DES encryption.
ENCRYPTION_ALGORITHM_3DES Uses triple DES encryption.
ENCRYPTION_ALGORITHM_AES128 Uses AES 128 encryption. (RSAES-OAEP)
ENCRYPTION_ALGORITHM_AES192 Uses AES 192 encryption. (RSAES-OAEP)
ENCRYPTION_ALGORITHM_AES256 Uses AES 256 encryption. (RSAES-OAEP)

Example

[Visual Basic, C#] The following example demonstrates how to send email with EASendMail SMTP Component. To get the full samples of EASendMail, please refer to Samples section.

[VB - Encrypt Email]
Dim oMail As SmtpMail = New SmtpMail("TryIt")
oMail.From = New MailAddress("test@adminsystem.com")
oMail.To = New AddressCollection( "encrypt1@adminsystem.com, encrypt2@adminsystem.com" )

' using RC2 Algorithm
oMail.EncryptionAlgorithm = EncryptionAlgorithmType.ENCRYPTION_ALGORITHM_RC2

Dim count As Integer = oMail.To.Count
For i As Integer = 0 To count - 1
    Dim oAddress As MailAddress = oMail.To(i)
    Try
//Find certificate by email adddress in My Other Peoples Store.
    //The certificate can be also imported by *.cer file like this: 
    //oMail.From.Certificate.Load("c:\encrypt1.cer")
    //Once the certificate is loaded to MailAddress, the email content will be encrypted
    automatically
        oAddress.Certificate.FindSubject(oAddress.Address, _
            Certificate.CertificateStoreLocation.CERT_SYSTEM_STORE_CURRENT_USER, _
            "AddressBook")
    Catch ep As Exception
        Try

            oAddress.Certificate.FindSubject(oAddress.Address, _
                Certificate.CertificateStoreLocation.CERT_SYSTEM_STORE_CURRENT_USER, _
                "My")
        Catch exp As Exception
            MessageBox.Show("No encryption certificate found for <" + oAddress.Address + ">:" + exp.Message)

        End Try
    End Try
Next

[C# - Encrypt Email]
SmtpMail oMail = new SmtpMail("TryIt");
oMail.From = "test@adminsystem.com";
oMail.To = "encrypt1@adminsystem.com, encrypt2@adminsystem.com";

// using RC2 Algorithm
oMail.EncryptionAlgorithm = EncryptionAlgorithmType.ENCRYPTION_ALGORITHM_RC2;

int count = oMail.To.Count;
for( int i = 0; i < count; i++ )
{
    MailAddress oAddress = oMail.To[i] as MailAddress;
    try
    {
//Find certificate by email adddress in My Other Peoples Store.
    //The certificate can be also imported by *.cer file like this: 
    //oMail.From.Certificate.Load("c:\\encrypt1.cer");
    //Once the certificate is loaded to MailAddress, the email content will be encrypted
    automatically
    
        oAddress.Certificate.FindSubject( oAddress.Address,
            Certificate.CertificateStoreLocation.CERT_SYSTEM_STORE_CURRENT_USER,
            "AddressBook" );
    }
    catch( Exception ep )
    {
        try
        {
            oAddress.Certificate.FindSubject( oAddress.Address,
                Certificate.CertificateStoreLocation.CERT_SYSTEM_STORE_CURRENT_USER,
                "My" );
        }
        catch( Exception exp )
        {
            MessageBox.Show( "No encryption certificate found for <" + oAddress.Address + ">:" + exp.Message );
        }
    }
}


[VB - Find Certificate in Active Directory by LDAP]
Dim oMail As SmtpMail = New SmtpMail("TryIt")
oMail.From = New MailAddress("test@adminsystem.com")
oMail.To = New AddressCollection( "Encryptor <encrypt@adminsystem.com>" )

' using RC2 Algorithm
oMail.EncryptionAlgorithm = EncryptionAlgorithmType.ENCRYPTION_ALGORITHM_RC2

Dim count As Integer = oMail.To.Count
For i As Integer = 0 To count - 1
    Dim oAddress As MailAddress = oMail.To(i)
    Try
        ' Please change the ldap path as your environment.
        oAddress.Certificate.FindSubject(oAddress.Address, _
            Certificate.CertificateStoreLocation.CERT_STORE_PROV_LDAP_STORE, _
            String.Format("ldap:///CN={0},CN=USERS,DC=my,DC=server?userCertificate", oAddress.Name))
    Catch exp As Exception
        MessageBox.Show("No encryption certificate found for <" + oAddress.Address + ">:" + exp.Message)

    End Try
Next

[C# - Find Certificate in Active Directory by LDAP]
SmtpMail oMail = new SmtpMail("TryIt");
oMail.From = "test@adminsystem.com";
oMail.To = ""Encryptor <encrypt@adminsystem.com>"";

// using RC2 Algorithm
oMail.EncryptionAlgorithm = EncryptionAlgorithmType.ENCRYPTION_ALGORITHM_RC2;

int count = oMail.To.Count;
for( int i = 0; i < count; i++ )
{
    MailAddress oAddress = oMail.To[i] as MailAddress;

    try
    {
        // Please change the ldap path as your environment.
        oAddress.Certificate.FindSubject( oAddress.Address,
            Certificate.CertificateStoreLocation.CERT_STORE_PROV_LDAP_STORE,
            String.Format("ldap:///CN={0},CN=USERS,DC=my,DC=server?userCertificate", oAddress.Name));
    }
    catch( Exception exp )
    {
        MessageBox.Show( "No encryption certificate found for <" + oAddress.Address + ">:" + exp.Message );
    }
}

See Also

SmtpMail.EncryptionAlgorithm Property
Digital Signature and E-mail Encryption
MailAddress.Certificate Property