我正在尝试将Dim certificate As X509Certificate2 = CodeFluent.Runtime.Utilities.Authenticode.FindSuitableCertificate()从VB.Net转换为C#,我知道它是X509Certificate2 AuthenticodeCert = CodeFluent.Runtime.Utilities.Authenticode.FindSuitableCertificate();
问题是,在C#中,它会产生一个ArgumentNullException,但在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}任何帮助都将不胜感激。谢谢。
发布于 2018-06-10 20:50:53
我想通了。
X509Certificate2 AuthenticodeCert = new X509Certificate2("PFX_Private_Key", "Password");唯一的问题是,如果它返回null,那么我就遇到了错误。唯一的补救办法似乎就是尝试接球。有没有人知道更好的空值编码方法?
谢谢。
发布于 2018-06-12 02:06:36
CodeFluent.Runtime库是一个独立于调用语言的.Net框架库。它本身是在C#中实现的。
因此,我怀疑您的问题与您使用的语言无关,而是与本地机器证书存储或执行的用户不同。
默认FindSuitableCertificate在My证书存储区中查找当前用户。如果将安装在计算机上的签名证书安装在其他位置,则可以使用另一个更高级的签名:
/// <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)https://stackoverflow.com/questions/50778605
复制相似问题