Skip to content

Instantly share code, notes, and snippets.

@rbrayb
Last active July 30, 2018 20:15
Show Gist options
  • Save rbrayb/2d7237242384b127cbe3b18a51c815a0 to your computer and use it in GitHub Desktop.
Save rbrayb/2d7237242384b127cbe3b18a51c815a0 to your computer and use it in GitHub Desktop.
// Headers e.g.
// string header2048 = "0602000000A40000525341310008000001000100";
private byte[] CreatePublicKey(byte[] publicKey)
{
byte[] publicKey = new byte[publicKey.Length];
byte[] header = null;
foreach (KeyValuePair<int, string> keyPair in headersList)
{
if (keyPair.Key == keySize)
header = ASCIIToBcd(Encoding.Default.GetBytes(keyPair.Value));
}
return publicKey
}
public static byte[] ASCIIToBcd(byte[] ASCII)
{
byte[] result = new byte[ASCII.Length / 2];
int i, j;
j = 0;
for (i = 0; i < ASCII.Length; i++)
{
if ((i % 2) == 0)
result[j] = (byte)(ASCIIToInt(ASCII[i]) << 4);
else
{
result[j] += (byte)(ASCIIToInt(ASCII[i]));
j++;
}
}
return result;
}
public static int ASCIIToInt(byte input)
{
if (input >= '0' && input <= '9')
return input - 48;
else if (input >= 'A' && input <= 'F')
return input - 55;
else if (input >= 'a' && input <= 'f')
return input - 87;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment