IoT中心HubManager-如何从后端更改设备的主键?

问题描述 投票:0回答:1

在Azure IoT后端中,如何使用Microsoft.Azure.Devices.RegistryManager(或其他类(如果需要的话)来更改设备的主键?

c# asp.net-core azure-iot-hub
1个回答
0
投票

以下行将回收设备对称密钥:

var device = registryManager.UpdateDeviceAsync(new Device(deviceId), true).Result;

仅更改设备主键的情况:

var device = registryManager.GetDeviceAsync(deviceId).Result;
var auth = new AuthenticationMechanism();
auth.SymmetricKey.PrimaryKey = "<new primary key>";
auth.SymmetricKey.SecondaryKey = device.Authentication.SymmetricKey.SecondaryKey;
device = registryManager.UpdateDeviceAsync(new Device(deviceId) { Authentication = auth}, true).Result;

或者您可以简化它:

var device = registryManager.GetDeviceAsync(deviceId).Result;
device.Authentication.SymmetricKey.PrimaryKey = "<new primary key>";
device = registryManager.UpdateDeviceAsync(device, true).Result;
© www.soinside.com 2019 - 2024. All rights reserved.