Click or drag to resize
MimeKit

DkimSigner(String, String, String, DkimSignatureAlgorithm) Constructor

Initialize a new instance of the DkimSigner class.

Namespace: MimeKit.Cryptography
Assembly: MimeKit (in MimeKit.dll) Version: 4.3.0
Syntax
C#
public DkimSigner(
	string fileName,
	string domain,
	string selector,
	DkimSignatureAlgorithm algorithm = DkimSignatureAlgorithm.RsaSha256
)

Parameters

fileName  String
The file containing the private key.
domain  String
The domain that the signer represents.
selector  String
The selector subdividing the domain.
algorithm  DkimSignatureAlgorithm  (Optional)
The signature algorithm.
Exceptions
ExceptionCondition
ArgumentNullException

fileName is null.

-or-

domain is null.

-or-

selector is null.

ArgumentExceptionfileName is a zero-length string, contains only white space, or contains one or more invalid characters.
FormatException The file did not contain a private key.
DirectoryNotFoundExceptionfileName is an invalid file path.
FileNotFoundException The specified file path could not be found.
UnauthorizedAccessException The user does not have access to read the specified file.
IOException An I/O error occurred.
Remarks

Creates a new DkimSigner.

Security note  Security Note
Due to the recognized weakness of the SHA-1 hash algorithm and the wide availability of the SHA-256 hash algorithm (it has been a required part of DKIM since it was originally standardized in 2007), it is recommended that RsaSha1 NOT be used.
Example
C#
public static void DkimSign (MimeMessage message)
{
    var headers = new HeaderId[] { HeaderId.From, HeaderId.Subject, HeaderId.Date };
    var signer = new DkimSigner ("privatekey.pem", "example.com", "brisbane", DkimSignatureAlgorithm.RsaSha256) {
HeaderCanonicalizationAlgorithm = DkimCanonicalizationAlgorithm.Simple,
BodyCanonicalizationAlgorithm = DkimCanonicalizationAlgorithm.Simple,
        AgentOrUserIdentifier = "@eng.example.com",
        QueryMethod = "dns/txt",
    };

    // Prepare the message body to be sent over a 7bit transport (such as older versions of SMTP).
    // Note: If the SMTP server you will be sending the message over supports the 8BITMIME extension,
    // then you can use `EncodingConstraint.EightBit` instead.
    message.Prepare (EncodingConstraint.SevenBit);

    signer.Sign (message, headers);
}
See Also