Microsoft example includes obsolete code: Why?
-
File this one under Weird (Weird Documentation) I was looking for a way to read the thumbprint of a X509 Certificate and found a perfect example at: X509Certificate2.Thumbprint Property (System.Security.Cryptography.X509Certificates) | Microsoft Learn[^] It's a nice compact sample where you pass in the path to the Cert and it prints out properties of the cert. However, there's a line in the code that I was curious about:
x509.Import(rawData);
Just Want To Read Properties of Cert Just wanted to make sure it wasn't importing the cert into my local cert store. I really don't want to do that. Just want to read properties. Microsoft Docs On X509.Import So I looked up the method in the docs (X509Certificate2.Import Method [^]) *Note, if you examine the URL you'll see that it includes view=net-8.0 (assuming that is referencing the latest .net 8.0 docs) Import Method is Marked Obsolete But then when you look at the docs the Import method is marked obsolete. But there doesn't seem to be any mention why. Since Import just imports the bytes of the certificate (doesn't import it into the cert store -- that is confusing naming):confused: I went ahead and ran the sample. Sample Ran Perfectly Fine Of course the sample ran fine and served my needs. But the "obsolete" thing is confusing. :confused: Not sure why there isn't a pointer to more updated sample. :confused::confused:
-
File this one under Weird (Weird Documentation) I was looking for a way to read the thumbprint of a X509 Certificate and found a perfect example at: X509Certificate2.Thumbprint Property (System.Security.Cryptography.X509Certificates) | Microsoft Learn[^] It's a nice compact sample where you pass in the path to the Cert and it prints out properties of the cert. However, there's a line in the code that I was curious about:
x509.Import(rawData);
Just Want To Read Properties of Cert Just wanted to make sure it wasn't importing the cert into my local cert store. I really don't want to do that. Just want to read properties. Microsoft Docs On X509.Import So I looked up the method in the docs (X509Certificate2.Import Method [^]) *Note, if you examine the URL you'll see that it includes view=net-8.0 (assuming that is referencing the latest .net 8.0 docs) Import Method is Marked Obsolete But then when you look at the docs the Import method is marked obsolete. But there doesn't seem to be any mention why. Since Import just imports the bytes of the certificate (doesn't import it into the cert store -- that is confusing naming):confused: I went ahead and ran the sample. Sample Ran Perfectly Fine Of course the sample ran fine and served my needs. But the "obsolete" thing is confusing. :confused: Not sure why there isn't a pointer to more updated sample. :confused::confused:
I think it has to do with the fact that mutable certificates are no longer considered secure. KB5025823 Change in how .NET applications import X.509 certificates - Microsoft Support[^]
-
I think it has to do with the fact that mutable certificates are no longer considered secure. KB5025823 Change in how .NET applications import X.509 certificates - Microsoft Support[^]
That's a good find and I appreciate you providing the link here. Once I read that, I remembered having to make a code change related to it back in 2021/2 because this functionality change was being reported ahead of time. It's too bad they didn't make that link more conspicuous in the Import method docs. Thanks again