简体   繁体   English

如何加密msmq消息?

[英]How to encrypt msmq messages?

For my internship i'm making an application which sends messages using MSMQ. 对于我的实习,我正在制作一个使用MSMQ发送消息的应用程序。 Everything works fine currently except the encryption. 除加密外,目前一切正常。 (Private data) (私人数据)

The application sends a list of a custom object to the server, and retrieves it from the server. 应用程序将自定义对象的列表发送到服务器,并从服务器检索它。 But when I use: message.UseEncryption = true; 但是当我使用:message.UseEncryption = true; the unittest won't run. unittest不会运行。

My code: 我的代码:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Messaging;
using System.Text;
using System.Threading.Tasks;

namespace MSMQClient
{
    public class ClientManager
    {
        public bool connected { get; private set; }
        public string queueLocation { get; private set; }

        public Message message { get; private set; }
        public MessageQueue messageQueue { get; private set; }
        public List<DataContracts.MemoryTransaction> notSentTransactions { get; private set; }

        public ClientManager()
        {
            queueLocation = @".\private$\testqueue";

            if (MessageQueue.Exists(queueLocation))
            {
                MessageQueue.Delete(queueLocation);
            }

            messageQueue = MessageQueue.Create(queueLocation);
            //messageQueue.EncryptionRequired = EncryptionRequired.Body;
        }

        public bool isConnected()
        {
            if (messageQueue != null)
            {
                return true;
            }
            return false;
        }

        public bool sendToServer(List<DataContracts.MemoryTransaction> memoryTransactions)
        {
            try
            {
                message = new Message();

                message.Formatter = new XmlMessageFormatter(new Type[] { typeof(List<DataContracts.MemoryTransaction>) });

                //message.UseEncryption = true;

                message.Body = memoryTransactions;
                message.Label = "MemoryTransList";
                message.Priority = MessagePriority.Normal;

                messageQueue.Send(message);
                return true;
            }
            catch (Exception ex)
            {
                Cocosoft.SDK.Logging.TextLogging(ex.ToString());

                notSentTransactions = memoryTransactions;

                return false;
            }
        }
    }

I found this site and tried a lot, but I can't get it working... I think I have to use the next things: 我找到了这个网站,并尝试了很多,但我无法让它工作......我想我必须使用下面的东西:

public bool sendToServer(List<DataContracts.MemoryTransaction> memoryTransactions)
{
    try
    {
        message = new Message();
        message.Body = ... //memoryTransactions
        message.Label = ... //"MemoryTransList"
        message.Priority = ... //Priority.Normal
        message.Formatter = ... //new XmlMessageFormatter(new Type[] { typeof(List<DataContracts.MemoryTransaction>) });
        message.UseEncryption = ... //true
        message.ConnectorType = ... //???
        message.EncryptionAlgorithm = ... //EncryptionAlgorithm.Rc2
        message.DestinationSymmetricKey = ...//???

        messageQueue.Send(message);
        return true;
    }
    catch (Exception ex)
    {
        notSentTransactions = memoryTransactions;
        return false;
    }
}

Who can help me? 谁能帮我? Am I missing something? 我错过了什么吗?

But the Cocosoft SDK saves this in a logging.txt: 但Cocosoft SDK将其保存在logging.txt中:

Translation: The specified format name does not support the requested operation. 转换:指定的格式名称不支持请求的操作。 For example, a direct queue format name cannot be deleted. 例如,无法删除直接队列格式名称。

System.Messaging.MessageQueueException (0x80004005): De opgegeven indelingsnaam ondersteunt de gevraagde bewerking niet. Een directe wachtrij-indelingsnaam kan bijvoorbeeld niet worden verwijderd.
   bij System.Messaging.MessageQueue.SendInternal(Object obj, MessageQueueTransaction internalTransaction, MessageQueueTransactionType transactionType)
   bij System.Messaging.MessageQueue.Send(Object obj)
   bij MSMQClient.ClientManager.sendToServer(List`1 memoryTransactions) in d:\StageGeert\UnitTestStage\MSMQClient\ClientManager.cs:regel 96

I found a solution! 我找到了解决方案! I was using a local version of MSMQ. 我使用的是本地版本的MSMQ。 But I had to implement in in Azure, so I used Azure Service Bus. 但是我必须在Azure中实现,所以我使用了Azure Service Bus。 This was a bit different then local message queuing. 这与本地消息排队有点不同。 But thanks to the Azure Service Bus, the problem is solved! 但是由于Azure Service Bus,问题解决了! Good Job Microsoft! 好工作微软!

If you set up message.UseEncryption = true; 如果你设置了message.UseEncryption = true; the Privacy Level of a target queue must be "Body" or "Optional". 目标队列的隐私级别必须是“正文”或“可选”。 If privacy level of a target queue is "None" - it will reject encrypted messages. 如果目标队列的隐私级别为“无” - 它将拒绝加密的消息。 https://msdn.microsoft.com/ru-ru/library/ms700286(v=vs.85).aspx https://msdn.microsoft.com/ru-ru/library/ms700286(v=vs.85).aspx

There is a checkbox in the computer management console for MSMQ that sets a message storage limit. 计算机管理控制台中有一个用于MSMQ的复选框,用于设置邮件存储限制。 Perhaps the encryption is forcing the messages to exceed this storage limit. 加密可能是强制消息超出此存储限制。 Can you try to uncheck the storage limits checkboxes to see if that allows you to properly send the messages? 您是否可以尝试取消选中存储限制复选框,以查看是否允许您正确发送邮件?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM