C# Azure IoT RegistryManager,阻止重用证书
我试图找出如果证书的指纹已经在另一台设备上使用,是否可以使用RegistryManager使其不注册设备C# Azure IoT RegistryManager,阻止重用证书,c#,azure,iot,C#,Azure,Iot,我试图找出如果证书的指纹已经在另一台设备上使用,是否可以使用RegistryManager使其不注册设备 _registryManager = RegistryManager.CreateFromConnectionString(_connectionString); Microsoft.Azure.Devices.Device device; try { Console.WriteLine
_registryManager = RegistryManager.CreateFromConnectionString(_connectionString);
Microsoft.Azure.Devices.Device device;
try
{
Console.WriteLine("Registering Device using X.509 certificate for authentication");
device = await _registryManager.AddDeviceAsync(new Microsoft.Azure.Devices.Device(deviceId)
{
Authentication = new AuthenticationMechanism()
{
X509Thumbprint = new X509Thumbprint()
{
PrimaryThumbprint = certificate2.Thumbprint
}
}
}).ConfigureAwait(false);
}
所以,如果上面的代码被调用,而另一个设备有那个指纹,我希望它失败。或者,我希望能够查看所有现有指纹,以便在注册前手动检查
我无法通过RegistryManager实现这一点
或者,我希望能够查看所有现有的指纹,以便
可以在注册前手动检查
您可以获得如下现有指纹:
var _registryManager = RegistryManager.CreateFromConnectionString(_connectionString);
var devices = await _registryManager.GetDevicesAsync(100); //Here I use 100 for testing purpose. Replace this value with yours.
foreach (var dev in devices)
{
if (dev.Authentication.X509Thumbprint.IsValid(false))
{
var primaryThumbprint = dev.Authentication.X509Thumbprint.PrimaryThumbprint;
var secondaryThumbprint = dev.Authentication.X509Thumbprint.SecondaryThumbprint;
Console.WriteLine("primaryThumbprint:" + primaryThumbprint);
Console.WriteLine("SecondaryThumbprint:" + SecondaryThumbprint);
}
}