Home > Net >  Get Thumbprint from Application keyCredential
Get Thumbprint from Application keyCredential

Time:06-04

I am fetching my organization's applications using the MS Graph API, and I am attempting to read the thumbprints of the certificates attached to each. It returns a byte[] but I can't seem to find the right encoding to convert to string.

The graph API returns a list of Application objects, which have a KeyCredentials enumerable, and finally a CustomKeyIdentifier, which should be the thumbprint. See this Microsoft page for more details on KeyCredentials.

The code I have tried is

System.Text.Encoding.ASCII.GetString(credential.CustomKeyIdentifier);

This returns gibberish characters, presumably because the encoding is incorrect, but I have tried every other encoding option available in Text.Encoding to no avail. How can I convert the CustomKeyIdentifier to a string?

CodePudding user response:

It should be a Base64 string so

System.Convert.ToBase64String(credential.CustomKeyIdentifier);

Or if you want the Hex version which is generally what people want when looking at the thumbprint it would be

BitConverter.ToString(credential.CustomKeyIdentifier).Replace("-","");
  • Related