因此,由于各种内部原因,我无法使用 NService Bus 的内置加密命令属性,而不得不将其实现为 MessageMutator。我的代码如下所示:
public class TransportMessageEncryptionMutator : IMutateTransportMessages
{
// Encryption helper is intialized with key stored in Key Vault.
private readonly EncryptionHelper encryptionHelper;
public void MutateOutgoing(LogicalMessage logicalMessage, TransportMessage transportMessage)
{
var encryptedBody = this.encryptionHelper.EncryptBytes(transportMessage.Body);
// Set the body of the message to be the encrypted copy of the data.
transportMessage.Body = encryptedBody;
}
public void MutateIncoming(TransportMessage transportMessage)
{
// Decrypt the body of the message.
var clearBody = this.encryptionHelper.DecryptBytes(transportMessage.Body);
// Set the body of the message to be the decrypted copy of the data and clear flag.
transportMessage.Body = clearBody;
}
}
这一切都运作良好,并且当它们被放入公共汽车时,它们会被加密。我正在尝试做的是能够在他们在 Particular 的 ServiceInsight 应用程序中查看消息时对其进行解密。我觉得他们提供了 IMutateTransportMessages 接口,并且在他们的网站上,特别提到了这样一个事实,即这是如何实现完整的消息加密;会有一种机制来为 ServiceInsight 创建一个插件来解密它。