grantwinney/GhostSharp

The byte conversion code in the auth flow can now be replaced by a built-in method

Closed this issue · 1 comments

This snippet of code:

public static byte[] StringToByteArray(string hex)
{
int NumberChars = hex.Length;
byte[] bytes = new byte[NumberChars / 2];
for (int i = 0; i < NumberChars; i += 2)
bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
return bytes;
}

Is now natively supported in .NET 5 and up through:

Convert.FromHexString()

See:
https://learn.microsoft.com/en-us/dotnet/api/system.convert.fromhexstring?view=net-6.0&WT.mc_id=DOP-MVP-5001511

Thanks for the heads up @jessehouwing! I made the replacement.