using System.Reflection; namespace Kit.Helpers { public class AssemblyHelper { public static void CheckSignatures() { // Получаем эталонный открытый ключ из текущей сборки Assembly currentAssembly = Assembly.GetExecutingAssembly(); var referencePublicKey = currentAssembly.GetName().GetPublicKey(); // Проверяем, что текущая сборка подписана if (referencePublicKey == null || referencePublicKey.Length == 0) { throw new ApplicationException("The current build is not signed."); } // Получаем список всех загруженных сборок var assemblies = AppDomain.CurrentDomain.GetAssemblies().OrderBy(x => x.FullName).ToList(); bool anyInvalid = false; // Проверяем каждую сборку foreach (var assembly in assemblies) { AssemblyName assemblyName = assembly.GetName(); var publicKey = assemblyName.GetPublicKey(); if (assemblyName.Name.ToLowerStartsWith("RiskProf") == false) { continue; } // Если сборка не подписана if (publicKey == null || publicKey.Length == 0) { anyInvalid = true; Console.WriteLine($"The assembly {assembly.FullName} is not signed."); } // Сравниваем открытый ключ с эталонным else if (referencePublicKey.SequenceEqual(publicKey) == false) { anyInvalid = true; Console.WriteLine($"The assembly {assembly.FullName} is signed with a different key."); } } if (anyInvalid) { throw new ApplicationException("Not all signatures match the signature of the current build."); } } } }