A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.mimekit.net/docs/html/M_MimeKit_Cryptography_ArcSigner_SignAsync_1.htm below:

ArcSignerSignAsync(FormatOptions, MimeMessage, IListString, CancellationToken) Method

ArcSignerSignAsync(FormatOptions, MimeMessage, IListString, CancellationToken) Method

Asynchronously digitally sign and seal a message using ARC.


Namespace: MimeKit.Cryptography
Assembly:

MimeKit (in MimeKit.dll) Version: 4.12.0

Syntax
public Task SignAsync(
	FormatOptions options,
	MimeMessage message,
	IList<string> headers,
	CancellationToken cancellationToken = default
)
Parameters
options  FormatOptions
The formatting options.
message  MimeMessage
The message to sign.
headers  IListString
The list of header fields to sign.
cancellationToken  CancellationToken  (Optional)
The cancellation token.
Return ValueTask

An awaitable task.

Exceptions Exception Condition ArgumentNullException

options is .

-or-

message is .

-or-

headers is .

ArgumentException

headers does not contain the 'From' header.

-or-

headers contains one or more of the following headers: Return-Path, Received, Comments, Keywords, Bcc, Resent-Bcc, or DKIM-Signature.

FormatException One or more ARC headers either did not contain an instance tag or the instance tag was invalid. Remarks

Asynchronously digitally signs and seals a message using ARC.

Example
using System;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;

using MimeKit;
using MimeKit.Cryptography;

namespace ArcSignerExample
{
    class ExampleArcSigner : ArcSigner
    {
        public ExampleArcSigner (Stream stream, string domain, string selector, DkimSignatureAlgorithm algorithm = DkimSignatureAlgorithm.RsaSha256) : base (stream, domain, selector, algorithm)
        {
        }

        public ExampleArcSigner (string fileName, string domain, string selector, DkimSignatureAlgorithm algorithm = DkimSignatureAlgorithm.RsaSha256) : base (fileName, domain, selector, algorithm)
        {
        }

        public ExampleArcSigner (AsymmetricKeyParameter key, string domain, string selector, DkimSignatureAlgorithm algorithm = DkimSignatureAlgorithm.RsaSha256) : base (key, domain, selector, algorithm)
        {
        }

        public string AuthenticationServiceIdentifier {
            get; set;
        }

        
        
        
        
        
        
        
        
        
        
        
        
        
        protected override AuthenticationResults GenerateArcAuthenticationResults (FormatOptions options, MimeMessage message, CancellationToken cancellationToken)
        {
            var results = new AuthenticationResults (AuthenticationServiceIdentifier);

            for (int i = 0; i < message.Headers.Count; i++) {
                var header = message.Headers[i];

                if (header.Id != HeaderId.AuthenticationResults)
                    continue;

                if (!AuthenticationResults.TryParse (header.RawValue, out AuthenticationResults authres))
                    continue;

                if (authres.AuthenticationServiceIdentifier != AuthenticationServiceIdentifier)
                    continue;

                foreach (var result in authres.Results) {
                    if (!results.Results.Any (r => r.Method == result.Method))
                        results.Results.Add (result);
                }
            }

            return results;
        }

        protected override Task<AuthenticationResults> GenerateArcAuthenticationResultsAsync (FormatOptions options, MimeMessage message, CancellationToken cancellationToken)
        {
            return Task.FromResult (GenerateArcAuthenticationResults (options, message, cancellationToken));
        }
    }

    class Program
    {
        public static void Main (string[] args)
        {
            if (args.Length < 2) {
                Help ();
                return;
            }

            for (int i = 0; i < args.Length; i++) {
                if (args[i] == "--help") {
                    Help ();
                    return;
                }
            }

            var headers = new HeaderId[] { HeaderId.From, HeaderId.Subject, HeaderId.Date };
            var signer = new ExampleArcSigner ("privatekey.pem", "example.com", "brisbane", DkimSignatureAlgorithm.RsaSha256) {
                HeaderCanonicalizationAlgorithm = DkimCanonicalizationAlgorithm.Simple,
                BodyCanonicalizationAlgorithm = DkimCanonicalizationAlgorithm.Simple,
                AgentOrUserIdentifier = "@eng.example.com",
            };

            if (!File.Exists (args[0])) {
                Console.Error.WriteLine ("{0}: No such file.", args[0]);
                return;
            }

            var message = MimeMessage.Load (args[0]);

            
            
            
            message.Prepare (EncodingConstraint.SevenBit);

            signer.Sign (message, headers);

            using (var stream = File.Create (args[1]))
                message.WriteTo (stream);
        }

        static void Help ()
        {
            Console.WriteLine ("Usage is: ArcSigner [options] [message] [output]");
            Console.WriteLine ();
            Console.WriteLine ("Options:");
            Console.WriteLine ("  --help               This help menu.");
        }
    }
}
See Also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4