Export (0) Print
Expand All

PublisherIdentityPermission Class

Represents the identity of a software publisher. This class cannot be inherited.

Namespace:  System.Security.Permissions
Assembly:  mscorlib (in mscorlib.dll)

[SerializableAttribute]
[ComVisibleAttribute(true)]
public sealed class PublisherIdentityPermission : CodeAccessPermission

Important noteImportant 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.

NoteNote:

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.

NoteNote:

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. 
using System;
using System.Security;
using System.Security.Permissions;
using System.Security.Cryptography.X509Certificates;
using System.IO;

public class PublisherIdentityPermissionDemo
{
    private static X509Certificate[] publisherCertificate = new X509Certificate[2];
    private static PublisherIdentityPermission publisherPerm1;
    private static PublisherIdentityPermission publisherPerm2;
    // Demonstrate all methods. 
    public static void Main(String[] args)
    {
        // Initialize the PublisherIdentityPermissions for use in the sample
        FileStream fs1 = new FileStream("..\\..\\..\\MyCert1.cer", FileMode.Open);
        Byte[] certSBytes1 = new Byte[(int)fs1.Length];
        fs1.Read(certSBytes1, 0, (int)fs1.Length);
        publisherCertificate[0] = new X509Certificate(certSBytes1);
        fs1.Close();
        FileStream fs2 = new FileStream("..\\..\\..\\MyCert2.cer", FileMode.Open);
        Byte[] certSBytes2 = new Byte[(int)fs2.Length];
        fs2.Read(certSBytes2, 0, (int)fs2.Length);
        publisherCertificate[1] = new X509Certificate(certSBytes2);
        fs2.Close();

        publisherPerm1 = new PublisherIdentityPermission(publisherCertificate[0]);
        publisherPerm2 = new PublisherIdentityPermission(publisherCertificate[1]);

        IsSubsetOfDemo();
        CopyDemo();
        UnionDemo();
        IntersectDemo();
        ToFromXmlDemo();

    }
    // IsSubsetOf determines whether the current permission is a subset of the specified permission. 
    private static void IsSubsetOfDemo()
    {

        if (publisherPerm2.IsSubsetOf(publisherPerm1))
        {
            Console.WriteLine(publisherPerm2.Certificate.Subject + " is a subset of " +
                publisherPerm1.Certificate.Subject);
        }
        else
        {
            Console.WriteLine(publisherPerm2.Certificate.Subject + " is not a subset of " +
                publisherPerm1.Certificate.Subject);
        }
    }
    // Union creates a new permission that is the union of the current permission and the specified permission. 
    private static void UnionDemo()
    {
        PublisherIdentityPermission publisherPerm3 = (PublisherIdentityPermission)publisherPerm1.Union(publisherPerm2);
        if (publisherPerm3 == null)
        {
            Console.WriteLine("The union of " + publisherPerm1 + " and " +
                publisherPerm2.Certificate.Subject + " is null.");
        }
        else
        {
            Console.WriteLine("The union of " + publisherPerm1.Certificate.Subject + " and " +
                publisherPerm2.Certificate.Subject + " = " +
                ((PublisherIdentityPermission)publisherPerm3).Certificate.Subject.ToString());
        }

    }
    // Intersect creates and returns a new permission that is the intersection of the current 
    // permission and the permission specified. 
    private static void IntersectDemo()
    {
        PublisherIdentityPermission publisherPerm3 = (PublisherIdentityPermission)publisherPerm1.Union(publisherPerm2);
        if (publisherPerm3 != null)
        {
            Console.WriteLine("The intersection of " + publisherPerm1.Certificate.Subject +
                " and " + publisherPerm2.Certificate.Subject + " = " +
                ((PublisherIdentityPermission)publisherPerm3).Certificate.Subject.ToString());
        }
        else
        {
            Console.WriteLine("The intersection of " + publisherPerm1.Certificate.Subject + " and " +
                publisherPerm2.Certificate.Subject + " is null.");
        }

    }
    //Copy creates and returns an identical copy of the current permission. 
    private static void CopyDemo()
    {
        // Create an empty PublisherIdentityPermission to serve as the target of the copy.
        publisherPerm2 = new PublisherIdentityPermission(PermissionState.None);
        publisherPerm2 = (PublisherIdentityPermission)publisherPerm1.Copy();
        Console.WriteLine("Result of copy = " + publisherPerm2.ToString());
    }
    // 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 static void ToFromXmlDemo()
    {
        publisherPerm2 = new PublisherIdentityPermission(PermissionState.None);
        publisherPerm2.FromXml(publisherPerm1.ToXml());
        Console.WriteLine("Result of ToFromXml = " +
            publisherPerm2.ToString());
    }
}

System.Object
  System.Security.CodeAccessPermission
    System.Security.Permissions.PublisherIdentityPermission

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft