Unobtrusive Property Encryption

Component: Message Property Encryption
NuGet Package NServiceBus.Encryption.MessageProperty (1.x)
Target NServiceBus Version: 6.x

Run the solution.

Two console applications will start up.


Which outputs

MessageWithSecretData sent.


Which outputs

I know the secret - it's 'betcha can't guess my secret'
SubSecret: My sub secret
CreditCard: 312312312312312 is valid to 3/11/2015 5:21:59 AM
CreditCard: 543645546546456 is valid to 3/11/2016 5:21:59 AM

Code walk-through

The message contract

Starting with the Shared project, open the MessageWithSecretData.cs file and look at the following code:

// Note all the properties to encrypt start with "Encrypted"
public class MessageWithSecretData :
    public string EncryptedSecret { get; set; }
    public MySecretSubProperty SubProperty { get; set; }
    public List<CreditCardDetails> CreditCards { get; set; }

public class MySecretSubProperty
    public string EncryptedSecret { get; set; }

public class CreditCardDetails
    public DateTime ValidTo { get; set; }
    public string EncryptedNumber { get; set; }

Encryption configuration

Open either one of the Program.cs. Notice the line


This code indicates that encryption should be enabled.

The key is then configured in the EncryptionExtensions.cs file using

public static void ConfigurationEncryption(this EndpointConfiguration endpointConfiguration)
    var encryptionService = new RijndaelEncryptionService(
        encryptionKeyIdentifier: "2015-10",
        key: Convert.FromBase64String("gdDbqRpqdRbTs3mhdZh9qCaDaxJXl+e6"));
        encryptedPropertyConvention: info =>
            return info.Name.StartsWith("Encrypted");

The message on the wire

Now run Endpoint1 on its own (i.e. don't start Endpoint2).

Open the .learningtransport folder for Samples.Encryption.Endpoint2 and view the message content.

The message will look like this:

<?xml version="1.0"?>

Last modified