Search code examples
c#.netcryptographyx509certificatex509certificate2

How to get FirendlyName of OIDs associated with X509Certificate2?


Is there a way to get friendly name for valid OID?

For example, I have OID 1.2.840.113549.1.1, which represents SHA1 with RSA signature. How to get friendly name that would X509Certificate2.SignatureAlgorithm.FriendlyName return?

I have tried to create var oid = new Oid("1.2.840.113549.1.1"), and looking into oid.FriendlyName property, it is null.


Solution

  • Not all OIDs have mapped FriendlyName values.

    1.2.840.113549.1.1 is the PKCS#1 arc, but it's never used directly, just as a namespace; so Windows apparently doesn't feel that it's useful to provide a FriendlyName value for it.

    sha1WithRsaEncryption is 1.2.840.113549.1.1.5 (or "{ pkcs-1 5 }", if you prefer), and new Oid("1.2.840.113549.1.1.5").FriendlyName will return "sha1RSA" on .NET Framework and .NET Core.

    For "most" OIDs the friendly name resolution is done by calling into the system cryptography libraries, but .NET Core hard codes that one, ensuring it maps the same on all OSes.