Am正在使用C#中的证书进行Message Queue身份验证。在MQ中,我已经注册了内部证书并使用了我的代码。请找到我的代码段。当我厌倦了附加数字签名和发件人证书时,MQ中不会收到我的消息。谁能帮我。我已使用此msdn URL作为参考。 https://msdn.microsoft.com/en-us/library/ms706312(v=vs.85).aspx。 计算机名称是我在以下代码中的IP地址。
代码:
using (MessageQueue messageQueue = new MessageQueue())
{
messageQueue.Path = "FormatName:DIRECT = TCP:" + ComputerName + "\\PRIVATE$\\" + “Test”;
System.Messaging.Message message = new System.Messaging.Message();
message.UseAuthentication = true;
message.UseEncryption = true;
message.EncryptionAlgorithm = EncryptionAlgorithm.Rc2;
string testMessage = "Test Sample Message";
SHA1Managed sHA1 = new SHA1Managed();
var hashValue = sHA1.ComputeHash(Encoding.Unicode.GetBytes(testMessage));
X509Certificate2 cert = new X509Certificate2(@"C:\Documents\MQCeritificate.cer");
RSA rsa = cert.GetRSAPublicKey();
var signature = rsa.Encrypt(hashValue, RSAEncryptionPadding.OaepSHA1);
message.DigitalSignature = signature;
message.ConnectorType = Guid.NewGuid();
message.CorrelationId = Message.Id;
message.AppSpecific = 1;
message.Label = "456";
message.SenderCertificate = cert.GetRawCertData();
message.Body = Convert.ToBase64String(hashValue);
messageQueue.Send(message);
}