Class DkimSignatureHeader
A parsed DKIM-Signature header (RFC 6376 §3.5). The header value is a semicolon-separated list of tag=value pairs. Tags are short alphanumeric strings. Whitespace is allowed around semicolons and equals signs.
Inherited Members
Namespace: DRIT.Mail.Rfc.Dkim
Assembly: DRIT.Mail.dll
Syntax
public sealed class DkimSignatureHeader
Constructors
View SourceDkimSignatureHeader(int, DkimSigningAlgorithm, string?, string?, DkimCanonicalizationMode, DkimCanonicalizationMode, string, IReadOnlyList<string>, string?, long?, string, string, DateTimeOffset?, DateTimeOffset?, IReadOnlyList<string>)
Initializes a new instance of the DkimSignatureHeader class with the specified tag values.
Declaration
public DkimSignatureHeader(int version, DkimSigningAlgorithm algorithm, string? signature, string? bodyHash, DkimCanonicalizationMode headerCanonicalization, DkimCanonicalizationMode bodyCanonicalization, string domain, IReadOnlyList<string> signedHeaders, string? identity, long? bodyLength, string queryMethod, string selector, DateTimeOffset? timestamp, DateTimeOffset? expiration, IReadOnlyList<string> copiedHeaders)
Parameters
| Type | Name | Description |
|---|---|---|
| int | version | |
| DkimSigningAlgorithm | algorithm | |
| string | signature | |
| string | bodyHash | |
| DkimCanonicalizationMode | headerCanonicalization | |
| DkimCanonicalizationMode | bodyCanonicalization | |
| string | domain | |
| IReadOnlyList<string> | signedHeaders | |
| string | identity | |
| long? | bodyLength | |
| string | queryMethod | |
| string | selector | |
| DateTimeOffset? | timestamp | |
| DateTimeOffset? | expiration | |
| IReadOnlyList<string> | copiedHeaders |
Properties
View SourceAlgorithm
Gets the signing algorithm (a=).
Declaration
public DkimSigningAlgorithm Algorithm { get; }
Property Value
| Type | Description |
|---|---|
| DkimSigningAlgorithm |
BodyCanonicalization
Gets the body canonicalization mode (c=, second part).
Declaration
public DkimCanonicalizationMode BodyCanonicalization { get; }
Property Value
| Type | Description |
|---|---|
| DkimCanonicalizationMode |
BodyHash
Gets the body hash (bh=, base64), or null if absent.
Declaration
public string? BodyHash { get; }
Property Value
| Type | Description |
|---|---|
| string |
BodyLength
Gets the body length count (l=), or null if not present.
Declaration
public long? BodyLength { get; }
Property Value
| Type | Description |
|---|---|
| long? |
CopiedHeaders
Gets the copied header fields (z=), pipe-separated list, or empty if absent.
Declaration
public IReadOnlyList<string> CopiedHeaders { get; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyList<string> |
Domain
Gets the signing domain (d=).
Declaration
public string Domain { get; }
Property Value
| Type | Description |
|---|---|
| string |
Expiration
Gets the signature expiration (x=), or null if absent.
Declaration
public DateTimeOffset? Expiration { get; }
Property Value
| Type | Description |
|---|---|
| DateTimeOffset? |
HeaderCanonicalization
Gets the header canonicalization mode (c=, first part).
Declaration
public DkimCanonicalizationMode HeaderCanonicalization { get; }
Property Value
| Type | Description |
|---|---|
| DkimCanonicalizationMode |
Identity
Gets the signer identity (i=), or null if absent.
Declaration
public string? Identity { get; }
Property Value
| Type | Description |
|---|---|
| string |
QueryMethod
Gets the query method (q=). Defaults to "dns/txt".
Declaration
public string QueryMethod { get; }
Property Value
| Type | Description |
|---|---|
| string |
Selector
Gets the selector (s=).
Declaration
public string Selector { get; }
Property Value
| Type | Description |
|---|---|
| string |
Signature
Gets the signature data (b=, base64), or null if absent.
Declaration
public string? Signature { get; }
Property Value
| Type | Description |
|---|---|
| string |
SignedHeaders
Gets the signed header fields (h=), colon-separated list.
Declaration
public IReadOnlyList<string> SignedHeaders { get; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyList<string> |
Timestamp
Gets the signature timestamp (t=), or null if absent.
Declaration
public DateTimeOffset? Timestamp { get; }
Property Value
| Type | Description |
|---|---|
| DateTimeOffset? |
Version
Gets the version tag (v=). MUST be 1.
Declaration
public int Version { get; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
View SourceParse(string)
Parses a DKIM-Signature header value (the part after "DKIM-Signature:").
Declaration
public static DkimSignatureHeader Parse(string headerValue)
Parameters
| Type | Name | Description |
|---|---|---|
| string | headerValue | The header value, possibly folded. |
Returns
| Type | Description |
|---|---|
| DkimSignatureHeader | The parsed DkimSignatureHeader. |
Exceptions
| Type | Condition |
|---|---|
| DkimException | Thrown if the header is malformed or a required tag is missing. |
ToString()
Serializes this header back to tag-value form (unfolded, single line, without the "DKIM-Signature:" prefix). Tags are emitted in a conventional order. The b= tag is included only if Signature is non-null.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string |
Overrides
View SourceToString(bool)
Serializes this header to tag-value form. When
includeSignature is false, the b= tag is emitted with
an empty value (used during signing and verification).
Declaration
public string ToString(bool includeSignature)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | includeSignature | The include signature used by the operation. |
Returns
| Type | Description |
|---|---|
| string |