If you want to encrypt an entire message, a message mutator is your best bet. However if you only want to encrypt certain properties within a message, you have another option:
public class MessageWithASecretCmd : ICommand
{
public string ClearText { get; set; }
public WireEncryptedString SecretText { get; set; }
}
Or if you'd like to use unobtrusive mode conventions:
public class MessageWithASecretCmd { public string ClearText { get; set; } public string SecretTextEncrypted { get; set; } } // Convention Definition Configure.Instance .DefiningEncryptedPropertiesAs(pi => pi.Name.EndsWith("Encrypted"));
In order to use property encryption, we will also need to enable it for the endpoint and configure the encryption key in the App.config
or Web.config
file:
// Endpoint configuration Configure.Instance.RijndaelEncryptionService(); // Configuration Section <section name="RijndaelEncryptionServiceConfig" type="NServiceBus.Config.RijndaelEncryptionServiceConfig, NServiceBus...