gpt4 book ai didi

c# - 如何加密msmq消息?

转载 作者:行者123 更新时间:2023-11-30 18:22:52 24 4
gpt4 key购买 nike

在我的实习期间,我正在制作一个使用 MSMQ 发送消息的应用程序。目前一切正常,除了加密。 (私有(private)数据)

应用程序将自定义对象的列表发送到服务器,并从服务器检索它。但是当我使用:message.UseEncryption = true;单元测试不会运行。

我的代码:

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;
}
}
}

我找到了 this site并尝试了很多,但我无法让它工作......我想我必须使用接下来的东西:

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 服务总线。这与本地消息队列有点不同。但多亏了 Azure Service Bus,问题解决了!微软干得好!

关于c# - 如何加密msmq消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33276505/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com