Message Property Encryption

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:

#pragma warning disable 618

public class MessageWithSecretData :
    public WireEncryptedString Secret { get; set; }
    public MySecretSubProperty SubProperty { get; set; }
    public List<CreditCardDetails> CreditCards { get; set; }

public class MySecretSubProperty
    public WireEncryptedString Secret { get; set; }

public class CreditCardDetails
    public DateTime ValidTo { get; set; }
    public WireEncryptedString Number { 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 encryptionKey = Convert.FromBase64String("gdDbqRpqdRbTs3mhdZh9qCaDaxJXl+e6");
#pragma warning disable 618
    // Property Encryption has been moved to an external nuget
    // package: NServiceBus.Encryption.MessageProperty
    // Old Encryption APIs marked obsolete in 6.2 of NServiceBus
    endpointConfiguration.RijndaelEncryptionService("2015-10", encryptionKey);

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