Message Body Encryption

Component: NServiceBus | Nuget: NServiceBus (Version: 5.x)

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

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

Edit
public class MessageEncryptor :
    IMutateTransportMessages
{
    public void MutateIncoming(TransportMessage transportMessage)
    {
        transportMessage.Body = transportMessage.Body.Reverse().ToArray();
    }

    public void MutateOutgoing(LogicalMessage logicalMessage, TransportMessage transportMessage)
    {
        transportMessage.Body = transportMessage.Body.Reverse().ToArray();
    }
}

The encrypting mutator must be injected into the container:

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

Samples

Related Articles


Last modified