X509 Certificate with Subject UID

守給你的承諾、 提交于 2021-01-24 08:17:18

问题


I am loading a certificate from string like this:

public static void Test()
{
    byte[] arrayCertificate;
    arrayCertificate = Convert.FromBase64String("CERT_STRING");
    X509Certificate2 clientCertificateFromXml = new X509Certificate2(arrayCertificate);
    Console.Write(clientCertificateFromXml);
    Console.ReadKey();
}

But this certificate doesn't have a "Subject Unique Identifier" Take a look at this:

http://en.wikipedia.org/wiki/X.509 (The part of Structure of a certificate)

And I want to know how can I read that value from my .NET code (I looked that I can get SerialNumber, Thumbprints and others but there is no Subject UID anywhere).

Also, I will really appreciate If anyone can share an openssl command to include this UID for the certificate :-) (pfx one)


回答1:


And I want to know how can I read that value from my .NET code

IIRC this is not exposed in the .NET BCL, either from X509Certificate or the newer (better but still incomplete) X509Certificate2.

But you can use Mono.Security assembly (or just the code you want from it), from the Mono project. It's open source, MIT.X11 licensed and it includes it's own X509Certificate.

This version expose just about everything in X.509 certificates, including a SubjectUniqueIdentifier property.

I will really appreciate If anyone can share an openssl command to include this UID for the certificate

I do not recall for openssl... but you can use the X509CertificateBuilder from Mono.Security to create your own certificates. See Mono's makecert tool source code for an example.

Disclaimer: I wrote the code :-)



来源:https://stackoverflow.com/questions/9999379/x509-certificate-with-subject-uid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!