Message Body Encryption

Component: NServiceBus
NuGet Package NServiceBus (7-pre)
This page targets a pre-release version and is subject to change prior to the final release.

Message encryption leverages the pipeline to encrypt the entire serialized message body.

One way of achieving this is by using a transport message mutator.

public class MessageEncryptor :
    IMutateIncomingTransportMessages,
    IMutateOutgoingTransportMessages
{
    public Task MutateIncoming(MutateIncomingTransportMessageContext context)
    {
        context.Body = context.Body.Reverse().ToArray();
        return Task.CompletedTask;
    }

    public Task MutateOutgoing(MutateOutgoingTransportMessageContext context)
    {
        context.OutgoingBody = context.OutgoingBody.Reverse().ToArray();
        return Task.CompletedTask;
    }
}

The encrypting mutator must be injected into the container:

endpointConfiguration.RegisterComponents(
    registration: components =>
    {
        components.ConfigureComponent<MessageEncryptor>(DependencyLifecycle.InstancePerCall);
    });

Samples

Related Articles


Last modified