Book Image

Learning NServiceBus - Second Edition

By : David Boike
Book Image

Learning NServiceBus - Second Edition

By: David Boike

Overview of this book

Table of Contents (18 chapters)
Learning NServiceBus Second Edition
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Property encryption


If your message contains certain information that should be encrypted, such as credit card numbers or other data you want to keep away from prying eyes, you can instruct NServiceBus to perform encryption on a property level:

public class MessageWithASecretCmd : ICommand
{
  public string ClearText { get; set; }
  public WireEncryptedString SecretText { get; set; }
}

If you'd like to use unobtrusive mode conventions, you can use this code:

public class MessageWithASecretCmd
{
  public string ClearText { get; set; }
  public string SecretTextEncrypted { get; set; }
}

// Convention Definition
cfg.Conventions()
  .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
cfg.RijndaelEncryptionService();

// Configuration Section
<section name="RijndaelEncryptionServiceConfig" type...