PublisherIdentityPermission Class
Represents the identity of a software publisher. This class cannot be inherited.
Assembly: mscorlib (in mscorlib.dll)
Important Note: |
|---|
In the .NET Framework versions 1.0 and 1.1, identity permissions cannot have an Unrestricted permission state value. In the .NET Framework version 2.0, identity permissions can have any permission state value. This means that in version 2.0, identity permissions have the same behavior as permissions that implement the IUnrestrictedPermission interface. That is, a demand for an identity always succeeds, regardless of the identity of the assembly, if the assembly has been granted full trust. For information on executing version 2.0 applications with version 1.1 code access security (CAS) policy, see <legacyV1CASPolicy> Element. In the .NET Framework versions 1.0 and 1.1, demands on the identity permissions are effective, even when the calling assembly is fully trusted. That is, although the calling assembly has full trust, a demand for an identity permission fails if the assembly does not meet the demanded criteria. In the .NET Framework version 2.0, demands for identity permissions are ineffective if the calling assembly has full trust. This assures consistency for all permissions, eliminating the treatment of identity permissions as a special case. |
Note: |
|---|
By default, code access security does not check for Publisher evidence. Unless your computer has a custom code group based on the PublisherMembershipCondition class, you can improve performance by bypassing Authenticode signature verification. This is accomplished by configuring the runtime to not provide Publisher evidence for code access security. For more information about how to configure this option and which applications can use it, see the <generatePublisherEvidence> element. |
The following code example shows the behavior of the PublisherIdentityPermission class methods.
Note: |
|---|
The code example is intended to show the behavior of the methods, not to demonstrate their use. In general, the methods of permission classes are used by the security infrastructure; they are not typically used in applications. Generally, only the constructors are used in application code. The created instance validates or controls resource access by using inherited CodeAccessPermission methods such as Demand. |
' To execute this sample you will need two certification files, MyCert1.cer and MyCert2.cer. ' The certification files can be created using the Certification Creation Tool, MakeCert.exe. Imports System Imports System.Security Imports System.Security.Permissions Imports System.Security.Cryptography.X509Certificates Imports System.IO Public Class PublisherIdentityPermissionDemo Private Shared publisherCertificate(1) As X509Certificate Private Shared publisherPerm1 As PublisherIdentityPermission Private Shared publisherPerm2 As PublisherIdentityPermission ' Demonstrate all methods. Public Shared Sub Main(ByVal args() As String) ' Initialize the PublisherIdentityPermissions for use in the sample Dim fs1 As New FileStream("..\..\..\MyCert1.cer", FileMode.Open) Dim certSBytes1(Fix(fs1.Length)) As [Byte] fs1.Read(certSBytes1, 0, Fix(fs1.Length)) publisherCertificate(0) = New X509Certificate(certSBytes1) fs1.Close() Dim fs2 As New FileStream("..\..\..\MyCert2.cer", FileMode.Open) Dim certSBytes2(Fix(fs2.Length)) As [Byte] fs2.Read(certSBytes2, 0, Fix(fs2.Length)) publisherCertificate(1) = New X509Certificate(certSBytes2) fs2.Close() publisherPerm1 = New PublisherIdentityPermission(publisherCertificate(0)) publisherPerm2 = New PublisherIdentityPermission(publisherCertificate(1)) IsSubsetOfDemo() CopyDemo() UnionDemo() IntersectDemo() ToFromXmlDemo() End Sub 'Main ' IsSubsetOf determines whether the current permission is a subset of the specified permission. Private Shared Sub IsSubsetOfDemo() If publisherPerm2.IsSubsetOf(publisherPerm1) Then Console.WriteLine(publisherPerm2.Certificate.Subject.ToString() + _ " is a subset of " + publisherPerm1.Certificate.Subject.ToString()) Else Console.WriteLine(publisherPerm2.Certificate.Subject.ToString() + _ " is not a subset of " + publisherPerm1.Certificate.Subject.ToString()) End If End Sub 'IsSubsetOfDemo ' Union creates a new permission that is the union of the current permission and the specified permission. Private Shared Sub UnionDemo() Dim publisherPerm3 As PublisherIdentityPermission = CType(publisherPerm1.Union(publisherPerm2), PublisherIdentityPermission) If publisherPerm3 Is Nothing Then Console.WriteLine("The union of " + publisherPerm1.ToString() + " and " _ + publisherPerm2.Certificate.Subject.ToString() + " is null.") Else Console.WriteLine("The union of " + publisherPerm1.Certificate.Subject.ToString() + _ " and " + publisherPerm2.Certificate.Subject.ToString() + " = " + _ CType(publisherPerm3, PublisherIdentityPermission).Certificate.Subject.ToString()) End If End Sub 'UnionDemo ' Intersect creates and returns a new permission that is the intersection of the current ' permission and the permission specified. Private Shared Sub IntersectDemo() Dim publisherPerm3 As PublisherIdentityPermission = CType(publisherPerm1.Union(publisherPerm2), PublisherIdentityPermission) If Not (publisherPerm3 Is Nothing) Then Console.WriteLine("The intersection of " + publisherPerm1.Certificate.Subject.ToString() + " = " + _ CType(publisherPerm3, PublisherIdentityPermission).Certificate.Subject.ToString()) Else Console.WriteLine("The intersection of " + publisherPerm1.Certificate.Subject.ToString() + _ " and " + publisherPerm2.Certificate.Subject.ToString() + " is null.") End If End Sub 'IntersectDemo 'Copy creates and returns an identical copy of the current permission. Private Shared Sub CopyDemo() ' Create an empty PublisherIdentityPermission to serve as the target of the copy. publisherPerm2 = New PublisherIdentityPermission(PermissionState.None) publisherPerm2 = CType(publisherPerm1.Copy(), PublisherIdentityPermission) Console.WriteLine("Result of copy = " + publisherPerm2.ToString()) End Sub 'CopyDemo ' ToXml creates an XML encoding of the permission and its current state; ' FromXml reconstructs a permission with the specified state from the XML encoding. Private Shared Sub ToFromXmlDemo() publisherPerm2 = New PublisherIdentityPermission(PermissionState.None) publisherPerm2.FromXml(publisherPerm1.ToXml()) Console.WriteLine("Result of ToFromXml = " + publisherPerm2.ToString()) End Sub 'ToFromXmlDemo End Class 'PublisherIdentityPermissionDemo
System.Security.CodeAccessPermission
System.Security.Permissions.PublisherIdentityPermission
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Important Note: