首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

如何验证已签名的DLL已经由我签名?

要验证已签名的DLL是否由您签名,您可以使用Windows操作系统自带的工具“Authenticode签名工具”。以下是详细步骤:

  1. 打开命令提示符(CMD)。sigcheck -i <DLL文件路径>将<DLL文件路径>替换为您要检查的DLL文件的路径。 3. 查看输出结果中的“Signature”一栏。如果DLL文件已签名,您将看到“Signed”字样。 4. 若DLL文件已签名,您可以查看“Signing Certificate”一栏,以确认签名者的身份。
  2. 输入以下命令并回车:

如果您需要使用编程方式验证DLL签名,您可以使用Windows API函数WinVerifyTrust。以下是一个简单的示例代码:

代码语言:csharp
复制
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;

public class Authenticode
{
    [DllImport("Wintrust.dll", ExactSpelling = true, SetLastError = false, CharSet = CharSet.Unicode)]
    static extern bool WinVerifyTrust(IntPtr hwnd, Guid pgActionID, WinTrustData pWVTData);

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
    struct WinTrustData
    {
        public uint StructSize;
        public IntPtr PolicyCallbackData;
        public IntPtr SIPClientData;
        public uint UIChoice;
        public uint RevocationChecks;
        public uint UnionChoice;
        public IntPtr FileOrCatalogOrBlobOrSgnrOrCert;
        public IntPtr StateAction;
        public IntPtr StateData;
        public string URLReference;
        public uint ProviderFlags;
        public uint UIContext;
        public string SignatureSettings;
    }

    const int WINTRUST_ACTION_GENERIC_VERIFY_V2 = 102;

    static bool Verify(string fileName)
    {
        WinTrustData wtd = new WinTrustData();
        wtd.StructSize = (uint)Marshal.SizeOf(typeof(WinTrustData));
        wtd.UnionChoice = 1;
        wtd.FileOrCatalogOrBlobOrSgnrOrCert = Marshal.StringToHGlobalUni(fileName);
        wtd.UIChoice = 2;

        bool result = WinVerifyTrust(IntPtr.Zero, new Guid("{00AAC56B-CD44-11d0-8CC2-00C04FC295EE}"), wtd);

        Marshal.FreeHGlobal(wtd.FileOrCatalogOrBlobOrSgnrOrCert);

        return result;
    }

    static void Main(string[] args)
    {
        string dllPath = @"C:\path\to\your\dll.dll";
        bool isVerified = Verify(dllPath);

        if (isVerified)
        {
            Console.WriteLine("DLL is signed and verified.");
        }
        else
        {
            Console.WriteLine("DLL is not signed or verification failed.");
        }
    }
}

这个示例代码使用WinAPI函数WinVerifyTrust来验证指定DLL文件的签名。如果验证成功,则返回true,否则返回false

请注意,这个示例代码仅供参考,实际应用中可能需要根据具体需求进行修改和调整。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

没有搜到相关的结果

领券