Search code examples
c#encryptionmessage-queuemsmqfips

MSMQ. Keep message body encrypted while it is stored on drive


My project require to keep all data encrypted, so MSMQ needs to be encrypted too. But as it is known from the article (https://msdn.microsoft.com/en-us/library/ms704178(v=vs.85).aspx ) messages from private queues are stored by default in …\MSMQ\Storage\p000000x.mq file.

When I configure a private queue, set its privacy level to "Body", and when I send encrypted message to this queue, then I open the …\MSMQ\Storage\p000000x.mq file in text viewer (I use Far Manager hex redactor), I see plain text of message. It is not encrypted. To send message I use next code:

message.UseEncryption = true;
message.EncryptionAlgorithm = EncryptionAlgorithm.Rc2;

The message …\MSMQ\Storage\p000000x.mq stays plain, despite message encryption specified. See the picture below.

enter image description here So my question: Is there some built-in tool to keep message encrypted on drive in …\MSMQ\Storage\p000000x.mq file? Or I need to encrypt message body before sending to queue, and then, when peek from the queue, I need to decrypt it?

Thanks a lot!


Solution

  • Yes, you will need to encrypt the data BEFORE putting it into a message and then decrypt the data AFTER reading the message.

    "Using Application Encryption on the Data" http://blogs.msdn.com/b/johnbreakwell/archive/2008/09/12/sending-encrypted-msmq-messages.aspx