0

I'm trying to convert Dim certificate As X509Certificate2 = CodeFluent.Runtime.Utilities.Authenticode.FindSuitableCertificate() from VB.Net to C# and I know that it's X509Certificate2 AuthenticodeCert = CodeFluent.Runtime.Utilities.Authenticode.FindSuitableCertificate();

The problem is that in C# it produces a ArgumentNullException, but works in VB.Net.

    X509Certificate2 AuthenticodeCert = Authenticode.FindSuitableCertificate(); // Problem
            // Check if there is a  Certificate in the Certificate Store that can signs code.
            if (Authenticode.CanSignCode(AuthenticodeCert) == true) // Problem ArgumentNullException
            {// Bla, Bla}

Any help would be Appreciated. Thanks.

DemarcPoint
  • 183
  • 1
  • 9

2 Answers2

0

I figured it out.

X509Certificate2 AuthenticodeCert = new X509Certificate2("PFX_Private_Key", "Password");

The only problem is if it returns null then I hit an error. The only remedying it seems for that was to Try Catch. Anyone know a better way to code for the null value?

Thanks.

DemarcPoint
  • 183
  • 1
  • 9
0

The CodeFluent.Runtime library is a .Net framework library independant of the calling language. It is itself implemented in C# .

So I suspect your issue is not related to the language you use, but the local machine certificate stores or the executing user that are different.

The default FindSuitableCertificate looks into the My certificate store for Current User. There is another more advanced signature you can use if the signing certificate installed on the machine is installed somewhere else instead :

    /// <summary>
    /// Finds a suitable certificate for authenticode signing.
    /// </summary>
    /// <param name="storeName">The store name.</param>
    /// <param name="storeLocation">The store location.</param>
    /// <param name="thumbPrint">The optional thumbprint. May be null.</param>
    /// <returns>A certificate instance or null if not found.</returns>
    public static X509Certificate2 FindSuitableCertificate(StoreName storeName, StoreLocation storeLocation, string thumbPrint)
MCR
  • 79
  • 1