Dart.Mail Namespace > MailMessage Class > SecureSign Method : SecureSign() Method |
Public Overloads Function SecureSign() As X509Certificate2Collection
Dim instance As MailMessage Dim value As X509Certificate2Collection value = instance.SecureSign()
public X509Certificate2Collection SecureSign()
public: X509Certificate2Collection* SecureSign();
public: X509Certificate2Collection^ SecureSign();
From is used to locate a signing certificate in the "MY" certificate store and X509IncludeOption.ExcludeRoot used. DigestAlgorithm.Sha256 is used for creating the message hash. A "detached" digital signature is created and included as an attachment.
Use SecureSign(X509Certificate2,X509IncludeOption,DigestAlgorithm,Boolean,Boolean) if additional control is desired.
using System.Security.Cryptography.X509Certificates; private MailMessage getSignedMessage(MailMessage message) { //Find the signing certificate in the "CurrentUser/My" certificate store //The following code results in the same signed message as "message.SecureSign();" X509Store myPersonalStore = new X509Store(StoreName.My, StoreLocation.CurrentUser); myPersonalStore.Open(OpenFlags.ReadOnly); foreach (X509Certificate2 certificate in myPersonalStore.Certificates) { if (certificate.Subject.Contains("E=" + message.From.ToString())) { //Sign the message message.SecureSign(certificate, X509IncludeOption.ExcludeRoot, DigestAlgorithm.Sha1, true, false); return message; } } return null; }
Imports System.Security.Cryptography.X509Certificates Private Function getSignedMessage(ByVal message As MailMessage) As MailMessage 'Find the signing certificate in the "CurrentUser/My" certificate store 'The following code results in the same signed message as "message.SecureSign();" Dim myPersonalStore As New X509Store(StoreName.My, StoreLocation.CurrentUser) myPersonalStore.Open(OpenFlags.ReadOnly) For Each certificate As X509Certificate2 In myPersonalStore.Certificates If certificate.Subject.Contains("E=" & message.From.ToString()) Then 'Sign the message message.SecureSign(certificate, X509IncludeOption.ExcludeRoot, DigestAlgorithm.Sha1, True, False) Return message End If Next certificate Return Nothing End Function