I am building a web application in C# to program Slot1 on a YubiKey for OTP. I am successfully able to program the key unless the configuration has been protected. The serial number was used to protect Slot1's configuration, but whenever I try to convert the serial number into the necessary Memory get 7 bytes and the .Execute() command complains about the max length accepted being 6 bytes... The serial number is 7 digits.
The error message is - {"Access code must be 6 or fewer bytes."}
I can't find any helpful information in the Yubico API documentation and was hoping someone here could assist. I need to be able to use the current access code (always the S/N) to overwrite Slot1 if its protected.
try
{
OtpSession otp_session = new OtpSession(_yubiKey);
Memory<byte> hmac_key = Generate_Seed();
Memory<byte> serial_number = new Memory<byte>();
serial_number = Encoding.ASCII.GetBytes(_yubiKey.SerialNumber.ToString());
SlotAccessCode access_code = new SlotAccessCode(serial_number);
using (OtpSession otp = new OtpSession(_yubiKey))
{
otp.ConfigureHotp(Slot.ShortPress)
.UseCurrentAccessCode(access_code)
.AppendCarriageReturn(true)
.UseNumericKeypad(true)
.UseKey(hmac_key)
.Execute();
}
}
catch (Exception ex)
{
if (ex.ToString() == "{YubiKey Operation Failed [Warning, state of non-volatile memory is
unchanged.]}")
lblMessage.Text = "YubiKey could not be configured. Please use the proper access
code.";
}