そのため、さまざまな内部的な理由から、コマンド プロパティに 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 が暗号化を解除するためのプラグインを作成するメカニズムがあること。