Show / Hide Table of Contents

How to delete a slot's configuration

Deleting a slot's configuration removes all credentials, associated counters (if any), slot settings, etc. To delete a slot's configuration, you must use one of two methods:

  • DeleteSlot(): for slots that are not configured with an access code.
  • DeleteSlotConfiguration(): for slots that are configured with an access code.
Note

These methods will fail if the slot you are attempting to delete is not configured.

Examples

Before running any of the code provided below, make sure you have already connected to a particular YubiKey on your host device via the YubiKeyDevice class.

To select the first available YubiKey connected to your host, use:

IEnumerable<IYubiKeyDevice> yubiKeyList = YubiKeyDevice.FindAll();

var yubiKey = yubiKeyList.First();

Deleting a slot configuration when an access code is not present

To delete a slot configuration that is not protected with an access code, use DeleteSlot(). You cannot chain other methods to DeleteSlot(), including Execute(). When calling DeleteSlot(), just provide the slot field (in this example, Slot.LongPress).

using (OtpSession otp = new OtpSession(yubiKey))
{
  otp.DeleteSlot(Slot.LongPress);
}

Deleting a slot configuration when an access code is present

To delete a slot configuration that is protected with an access code, you must call DeleteSlotConfiguration and provide the current access code with UseCurrentAccessCode(). You cannot set a new access code during this operation--calling SetNewAccessCode() will succeed, but the operation will not be applied.

Unlike DeleteSlot(), DeleteSlotConfiguration() requires Execute() for the operation to apply the changes.

using (OtpSession otp = new OtpSession(yubiKey))
{
  ReadOnlyMemory<byte> currentAccessCodeBytes = new byte[SlotAccessCode.MaxAccessCodeLength] { 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, };
  SlotAccessCode currentAccessCode = new SlotAccessCode(currentAccessCodeBytes);

  otp.DeleteSlotConfiguration(Slot.LongPress)
    .UseCurrentAccessCode(currentAccessCode)
    .Execute();
}
  • Improve this Doc
In this article
Back to top Generated by DocFX