0
因此,出於各種內部原因,我無法使用NService總線的內置加密命令屬性,而是必須將其實施爲MessageMutator。我看起來像這樣的代碼:特殊的ServiceInsight通過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;
}
}
這一切都很好,當他們被放入公交車時,事情都被加密。我試圖做的是能夠在特定的ServiceInsight應用程序中查看消息時解密消息。我覺得他們在他們的網站上提供IMutateTransportMessages接口的事實,特別暗示這是如何實現完整的消息加密的事實;有一種機制可以爲ServiceInsight創建一個插件來解密它。