[英]How to encrypt msmq messages?
对于我的实习,我正在制作一个使用MSMQ发送消息的应用程序。 除加密外,目前一切正常。 (私人数据)
应用程序将自定义对象的列表发送到服务器,并从服务器检索它。 但是当我使用:message.UseEncryption = true; unittest不会运行。
我的代码:
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;
}
}
}
我找到了这个网站,并尝试了很多,但我无法让它工作......我想我必须使用下面的东西:
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;
}
}
谁能帮我? 我错过了什么吗?
但Cocosoft SDK将其保存在logging.txt中:
转换:指定的格式名称不支持请求的操作。 例如,无法删除直接队列格式名称。
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
我找到了解决方案! 我使用的是本地版本的MSMQ。 但是我必须在Azure中实现,所以我使用了Azure Service Bus。 这与本地消息排队有点不同。 但是由于Azure Service Bus,问题解决了! 好工作微软!
如果你设置了message.UseEncryption = true; 目标队列的隐私级别必须是“正文”或“可选”。 如果目标队列的隐私级别为“无” - 它将拒绝加密的消息。 https://msdn.microsoft.com/ru-ru/library/ms700286(v=vs.85).aspx
计算机管理控制台中有一个用于MSMQ的复选框,用于设置邮件存储限制。 加密可能是强制消息超出此存储限制。 您是否可以尝试取消选中存储限制复选框,以查看是否允许您正确发送邮件?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.