Dart.Mail Namespace > MailMessage Class > SecureDecode Method : SecureDecode() Method |
Public Overloads Function SecureDecode() As SignerInfoCollection
Dim instance As MailMessage Dim value As SignerInfoCollection value = instance.SecureDecode()
public SignerInfoCollection SecureDecode()
public: SignerInfoCollection* SecureDecode();
public: SignerInfoCollection^ SecureDecode();
If IsSecure is true, this method verifies and/or decrypts the S/MIME message in place. If successful, IsSecure returns false. If unsuccessful, an Exception is thrown; decryption may succeed before signer verification throws an exception, so the message may be partially decoded if an exception is thrown.
This method will search the "MY" certificate store for a valid decrypting certificate as necessary, and imports the message's signing certificates into the "AddressBook" certificate store where they may subsequently be used by SecureEncrypt
To verify the digital signature or validate the certificate, call SignerInfo.CheckSignature(Boolean) on each member of the returned System.Security.Cryptography.Pkcs.SignerInfoCollection.
Use SecureDecode(X509Certificate2Collection,Boolean) if additional control is desired.
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.Pkcs; private MailMessage getDecodedMessage(MailMessage message) { //Load the decrypting certificate from an exported certificate file (may also be loaded from an X509Store) X509Certificate2 decryptingCertificate = new X509Certificate2(Application.StartupPath + "\\myCertificate.pfx"); //Decode the message and import the signing certificate into the AddressBook certificate Store //(If the decrypting certificate is already present in the "MY" certificate store, //the parameterless SecureDecode() may be used instead.) SignerInfoCollection signatories = message.SecureDecode(new X509Certificate2Collection(decryptingCertificate), true); //Optionally verify the signature and validate the certificate foreach (SignerInfo signator in signatories) signator.CheckSignature(false); return message; }
Imports System.Security.Cryptography.X509Certificates Imports System.Security.Cryptography.Pkcs Private Function getDecodedMessage(ByVal message As MailMessage) As MailMessage 'Load the decrypting certificate from an exported certificate file (may also be loaded from an X509Store) Dim decryptingCertificate As New X509Certificate2(Application.StartupPath & "\myCertificate.pfx") 'Decode the message and import the signing certificate into the AddressBook certificate Store '(If the decrypting certificate is already present in the "MY" certificate store, 'the parameterless SecureDecode() may be used instead.) Dim signatories As SignerInfoCollection = message.SecureDecode(New X509Certificate2Collection(decryptingCertificate), True) 'Optionally verify the signature and validate the certificate For Each signator As SignerInfo In signatories signator.CheckSignature(False) Next signator Return message End Function