Message Body Encryption

Component: NServiceBus
NuGet NServiceBus (3.x)
Standard support for version 3.x of NServiceBus has expired. For more information see our Support Policy.

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 :
    IMutateTransportMessages
{
    public void MutateIncoming(TransportMessage transportMessage)
    {
        transportMessage.Body = transportMessage.Body.Reverse().ToArray();
    }

    public void MutateOutgoing(object[] messages, TransportMessage transportMessage)
    {
        transportMessage.Body = transportMessage.Body.Reverse().ToArray();
    }
}

The encrypting mutator must be injected into the container:

var configureComponents = configuration.Configurer;
configureComponents.ConfigureComponent<MessageEncryptor>(DependencyLifecycle.InstancePerCall);

Samples

Related Articles


Last modified