title: How to authenticate IoT device using X509Certificate
body: <p>I was following <a href="https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-security-x509-get-started" rel="nofollow noreferrer">this</a> tutorial on 'Azure IoT hub using the X.509 Certificate Authentication'. The sample console app works fine and I was able to send a message to my existing IoThub. However, when I try to connect with my existing IoThub from my UWP using the same code, the same certificate and from the same device, I keep getting non specific exception Message = "Exception from HRESULT: 0x80072F0C". I was wondering what is the basic difference between UWP and console app when connecting with IoT hub using X.509 Certificate. </p>
  
  <pre><code>X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
  store.Open(OpenFlags.ReadOnly);
  var certs = store.Certificates.Find(X509FindType.FindByThumbprint, "thumbprint", false);
  if (certs.Count &gt; 0 &amp;&amp; certs[0].HasPrivateKey)
  {
      var auth = new DeviceAuthenticationWithX509Certificate("deviceId", "X509Certificate2");
      deviceClient = DeviceClient.Create("***.azure-devices.net", auth, TransportType.Amqp);
  
      var message = new Message(Encoding.ASCII.GetBytes("Hello"));
      await deviceClient.SendEventAsync(message);
      outMessage = await ReceiveCloudMessageAsync();
  }
  else
  {
       throw new Exception("cert not found");
  }
  </code></pre>
  
  <p>I was able to get the self-signed cert and has the private key but an exception is being thrown at 'SendEventAsync'.</p>