Skip to content

C# Library for validating File Authenticode Signatures in Windows.

License

Notifications You must be signed in to change notification settings

imerzan/AuthentiSharp

Repository files navigation

AuthentiSharp

C# Library for validating File Authenticode Signatures in Windows.

Examples

using AuthentiSharp;

namespace Example
{
    public static void Example1()
    {
        try
        {
            if (!Authenticode.Verify(Process.GetCurrentProcess().MainModule.FileName)) // Only checks authenticode signature
                throw new Exception();
        }
        catch
        {
            Environment.FailFast("Assembly Tampering Detected!");
        }
    }

    public static void Example2()
    {
        try
        {
            if (!Authenticode.VerifyFull(Process.GetCurrentProcess().MainModule.FileName,
            (cert, chain) => // Also checks certificate validity via custom callback
            {
                chain.ChainPolicy = new()
                {
                    RevocationMode = X509RevocationMode.Online,
                    RevocationFlag = X509RevocationFlag.ExcludeRoot
                };
                if (!chain.Build(cert))
                    return false;
                if (!cert.Thumbprint.Equals("YourExpectedThumbprint", StringComparison.OrdinalIgnoreCase))
                    return false;
                return true;
            }))
                throw new Exception();
        }
        catch
        {
            Environment.FailFast("Assembly Tampering Detected!");
        }
    }
}

Install via Nuget

AuthentiSharp

About

C# Library for validating File Authenticode Signatures in Windows.

Resources

License

Stars

Watchers

Forks

Languages