簡體   English   中英

IoT 中心 RegistryManager - 如何從后端更改設備的主鍵?

[英]IoT hub RegistryManager - How to change device's primary key from backend?

在 Azure IoT 后端,我如何使用 Microsoft.Azure.Devices.RegistryManager(或其他類,如果這是我需要的)來更改設備的主鍵?

以下行將回收設備對稱密鑰:

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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM