You can use PublisherIdentityPermissionAttribute .
If you apply the PublisherIdentityPermissionAttribute class to the MyClass class, then only classes in assemblies signed by the mycert.cer certificate can use your class. You need to put SecurityAction.Demand
All callers above the call stack must be granted the permission indicated by the current permission object
Use as
[PublisherIdentityPermission(SecurityAction.Demand, CertFile = "mycert.cer")] public class MyClass
You can also use it at the assembly level to protect the entire assembly (however, assembly-level security will not work with .Net 4.0 unless you set <NetFx40_LegacySecurityPolicy enabled="true"/> in the configuration).
source share