-
The following code works under .NET 8 (on Windows) and prints var cert = X509Certificate.CreateFromSignedFile(@"C:\Windows\explorer.exe");
Console.WriteLine(cert.Issuer); Under .NET 9, compiling that code gives the warning:
Firstly, I don't completely understand the warning, because I'm not using a constructor or I've read #91763, dotnet/docs#41662, and https://learn.microsoft.com/en-us/dotnet/fundamentals/syslib-diagnostics/syslib0057#workaround but I haven't seen a replacement given for this specific method.
What is the right, non-obsolete way to check an Authenticode signature in .NET 9? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
Is the answer to install Microsoft.Security.Extensions and do the following? using var stream = File.OpenRead(@"C:\Windows\explorer.exe");
var signatureInfo = FileSignatureInfo.GetFromFileStream(stream);
Console.WriteLine(signatureInfo.SigningCertificate.Issuer); That is, has this functionality moved out of core .NET in .NET 9 and now needs to be supplied by a NuGet package? |
Beta Was this translation helpful? Give feedback.
That package is not the recommended answer, because I don't know where it comes from. It might be fine, I just couldn't establish confidence in its maintenance with 2 minutes of looking.
The recommended answer, if you're wanting to extract the Authenticode signer, is to combine GetCertContentType and the ctor and suppress the warning. The reason CreateFromSignedFile is included in the obsoletion is that it doesn't only load Authenticode, it's always been a poorly named vanity wrapper around the "do everything" constructor (it's just implemented as
return new X509Certificate2(path)
)