title: Message Queue Authentication By Certificate - C#
body: <p>Am working on Message Queue authentication by certificate in C#. In MQ, I have registered the internal certificate and used it my code. Please find my code snippet. When I tired to attach digital signature and sender certificate, my message is not received in MQ. Can any one help me. I have used this msdn URL for my reference. <a href="https://msdn.microsoft.com/en-us/library/ms706312(v=vs.85).aspx" rel="nofollow noreferrer">https://msdn.microsoft.com/en-us/library/ms706312(v=vs.85).aspx</a>.
  Computer name is my ip address in the below code.</p>
  
  <p>Code :</p>
  
  <pre><code>    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);
  }
  </code></pre>