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
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class PublisherIdentityPermission extends CodeAccessPermission
SerializableAttribute 
ComVisibleAttribute(true) 
public final class PublisherIdentityPermission extends CodeAccessPermission
Not applicable.

NoteImportant:

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

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.

using System;
using System.Security;
using System.Security.Permissions;
using System.Security.Cryptography.X509Certificates;
using System.IO;

[assembly: CLSCompliant(true)]

public class PublisherIdentityDemo
{

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

        bool retCode = true;

        String publisher1, publisher2;
        PublisherIdentityPermission pubIdPerm1, pubIdPerm2;

        PublisherGenerator pubGen1 = new PublisherGenerator();
        PublisherGenerator pubGen2 = new PublisherGenerator();

        pubGen1.ResetIndex();
        while (pubGen1.CreatePublisher(out pubIdPerm1, out publisher1))
        {
            if (pubIdPerm1 == null) continue;
            pubGen2.ResetIndex();
            while (pubGen2.CreatePublisher(out pubIdPerm2, out publisher2))
            {
                if (pubIdPerm2 == null) continue;

                try
                {
                    // Check for whether either of the publishers is null.
                    // An exception will be thrown if either is null.
                    if (publisher1 != "null" && publisher2 != "null")
                    {
                        if (pubIdPerm1.IsSubsetOf(pubIdPerm2))
                        {
                            Console.WriteLine(pubIdPerm1.Certificate.GetName() +
                                " is a subset of " + pubIdPerm2.Certificate.GetName() + "\n");
                        }
                        else
                        {
                            Console.WriteLine(pubIdPerm1.Certificate.GetName() +
                                " is not a subset of " + pubIdPerm2.Certificate.GetName() + "\n");
                        }
                    }

                }
                catch
                {
                    Console.WriteLine("An exception was thrown for " + publisher1 + " is a subset of " +
                        publisher2 + "\n.");
                    retCode = false;
                }

            }
        }


        return retCode;
    }
    // Union creates a new permission that is the union of the current permission and the specified permission.
    private bool UnionDemo()
    {

        bool retCode = true;

        String publisher1, publisher2;
        PublisherIdentityPermission pubIdPerm1, pubIdPerm2;
        IPermission p3;

        PublisherGenerator pubGen1 = new PublisherGenerator();
        PublisherGenerator pubGen2 = new PublisherGenerator();

        pubGen1.ResetIndex();
        while (pubGen1.CreatePublisher(out pubIdPerm1, out publisher1))
        {
            if (pubIdPerm1 == null | pubIdPerm1.Certificate == null) continue;
            pubGen2.ResetIndex();
            while (pubGen2.CreatePublisher(out pubIdPerm2, out publisher2))
            {
                if (pubIdPerm2 == null | pubIdPerm2.Certificate == null) continue;
                try
                {
                    p3 = pubIdPerm1.Union(pubIdPerm2);

                    if (p3 != null)
                    {
                        Console.WriteLine("The union of " + pubIdPerm1.Certificate.GetName() + " and "
                            + pubIdPerm2.Certificate.GetName() + " = "
                            + ((PublisherIdentityPermission)p3).Certificate.GetName());
                    }
                    else
                    {
                        Console.WriteLine("The union of " + pubIdPerm1.Certificate.GetName() + " and "
                            + pubIdPerm2.Certificate.GetName() + " = null.");
                    }
                }
                catch (Exception e)
                {
                    // Expected exception.
                    Console.WriteLine("An exception was thrown for union :" + e.Message + "\n");
                }


            }
        }


        return retCode;

    }
    // Intersect creates and returns a new permission that is the intersection of the
    // current permission and the permission specified.
    private bool IntersectDemo()
    {

        bool retCode = true;

        String publisher1, publisher2;
        PublisherIdentityPermission pubIdPerm1, pubIdPerm2, p3;

        PublisherGenerator pubGen1 = new PublisherGenerator();
        PublisherGenerator pubGen2 = new PublisherGenerator();

        pubGen1.ResetIndex();
        while (pubGen1.CreatePublisher(out pubIdPerm1, out publisher1))
        {
            if (pubIdPerm1 == null | pubIdPerm1.Certificate == null) continue;
            pubGen2.ResetIndex();
            while (pubGen2.CreatePublisher(out pubIdPerm2, out publisher2))
            {
                if (pubIdPerm2 == null | pubIdPerm2.Certificate == null) continue;
                p3 = (PublisherIdentityPermission)pubIdPerm1.Intersect(pubIdPerm2);
                if (p3 != null && p3.Certificate != null)
                {

                    Console.WriteLine("The intersection of " + pubIdPerm1.Certificate.GetName() + " and " +
                        pubIdPerm2.Certificate.GetName() + " = " +
                        ((PublisherIdentityPermission)p3).Certificate.GetName());
                }
                else
                {
                    Console.WriteLine("The intersection of " + pubIdPerm1.Certificate.GetName() + " and " +
                        pubIdPerm2.Certificate.GetName() + " is null.");
                }

            }
        }


        return retCode;

    }
    ////Copy creates and returns an identical copy of the current permission.
    private bool CopyDemo()
    {

        bool retCode = true;

        String publisher1;
        PublisherIdentityPermission pubIdPerm1, pubIdPerm2;

        PublisherGenerator pubGen1 = new PublisherGenerator();
        PublisherGenerator pubGen2 = new PublisherGenerator();

        pubGen1.ResetIndex();
        while (pubGen1.CreatePublisher(out pubIdPerm1, out publisher1))
        {
            if (pubIdPerm1 == null) continue;
            pubGen2.ResetIndex();
            try
            {
                pubIdPerm2 = (PublisherIdentityPermission)pubIdPerm1.Copy();
                if (pubIdPerm2 != null)
                {
                    Console.WriteLine("Result of copy = " + pubIdPerm2.ToString() + "\n");
                }
                else
                {
                    Console.WriteLine("Result of copy is null. \n");
                }


            }
            catch (Exception e)
            {
                Console.WriteLine("Copy failed :" + pubIdPerm1.ToString() + e);
                continue;
            }

        }


        return retCode;

    }
    // 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 bool ToFromXmlDemo()
    {

        bool retCode = true;

        String publisher1;
        PublisherIdentityPermission pubIdPerm1, pubIdPerm2;

        PublisherGenerator pubGen1 = new PublisherGenerator();
        PublisherGenerator pubGen2 = new PublisherGenerator();

        pubGen1.ResetIndex();
        while (pubGen1.CreatePublisher(out pubIdPerm1, out publisher1))
        {
            if (pubIdPerm1 == null) continue;
            pubGen2.ResetIndex();
            try
            {
                pubIdPerm2 = new PublisherIdentityPermission(PermissionState.None);
                pubIdPerm2.FromXml(pubIdPerm1.ToXml());
                Console.WriteLine("Result of ToFromXml = " + pubIdPerm2.ToString() + "\n");
            }
            catch (Exception e)
            {
                Console.WriteLine("ToFromXml failed :" + pubIdPerm1.ToString() + e);
                continue;
            }


        }

        return retCode;

    }

    // Invoke all demos.
    public bool RunDemo()
    {

        bool ret = true;
        bool retTmp;

        // Call the IsSubsetOf demo.
        if (retTmp = IsSubsetOfDemo()) Console.Out.WriteLine("IsSubsetOf demo completed successfully.");
        else
            Console.Out.WriteLine("IsSubsetOf demo failed.");
        ret = retTmp && ret;
        Console.WriteLine("************************************************************************");

        // Call the Union demo.
        if (retTmp = UnionDemo()) Console.Out.WriteLine("Union demo completed successfully.");
        else
            Console.Out.WriteLine("Union demo failed.");
        ret = retTmp && ret;
        Console.WriteLine("************************************************************************");

        // Call the Intersect demo.
        if (retTmp = IntersectDemo()) Console.Out.WriteLine("Intersect demo completed successfully.");
        else
            Console.Out.WriteLine("Intersect demo failed.");
        ret = retTmp && ret;
        Console.WriteLine("************************************************************************");


        // Call the Copy demo.
        if (retTmp = CopyDemo()) Console.Out.WriteLine("Copy demo completed successfully. ");
        else
            Console.Out.WriteLine("Copy demo failed.");
        ret = retTmp && ret;
        Console.WriteLine("************************************************************************");

        // Call the ToFromXml demo
        if (retTmp = ToFromXmlDemo()) Console.Out.WriteLine("ToFromXml demo completed successfully.");
        else
            Console.Out.WriteLine("ToFromXml demo failed.");
        ret = retTmp && ret;
        Console.WriteLine("************************************************************************");

        return ret;
    }
    // Test harness.
    public static void Main(String[] args)
    {

        try
        {
            PublisherIdentityDemo democase = new PublisherIdentityDemo();
            bool ret = democase.RunDemo();
            if (ret)
            {
                Console.Out.WriteLine("The PublisherIdentityPermission demo completed successfully.");
                Console.Out.WriteLine("Press the Enter key to exit.");
                string consoleInput = Console.ReadLine();
                System.Environment.ExitCode = 100;
            }
            else
            {
                Console.Out.WriteLine("The PublisherIdentityPermission demo failed.");
                Console.Out.WriteLine("Press the Enter key to exit.");
                string consoleInput = Console.ReadLine();
                System.Environment.ExitCode = 101;
            }
        }
        catch (Exception e)
        {
            Console.Out.WriteLine("The PublisherIdentityPermission demo failed.");
            Console.WriteLine(e.ToString());
            Console.Out.WriteLine("Press the Enter key to exit.");
            string consoleInput = Console.ReadLine();
            System.Environment.ExitCode = 101;
        }
    }
}


// This class generates PublisherIdentityPermission objects.

internal class PublisherGenerator
{
    private X509Certificate[] publisherCertificate = new X509Certificate[2];
    private int publisherIndex = 0;

    public PublisherGenerator()
    {

        try
        {
            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();

            ResetIndex();

        }
        catch (Exception e)
        {

            Console.WriteLine("Cannot create certificate : " + e);
            Console.Out.WriteLine("PublisherIdentityPermission demo failed.");
            System.Environment.ExitCode = 101;

        }
    }

    public void ResetIndex()
    {

        publisherIndex = 0;

    }
    // CreatePublisher creates a PublisherIdentityPermission.
    public bool CreatePublisher(out PublisherIdentityPermission publisherPerm, out String publisher)
    {

        if (publisherIndex >= publisherCertificate.Length + 1)
        {
            publisherPerm = null;
            publisher = "null";
            return false;
        }

        if (publisherIndex >= publisherCertificate.Length)
        {
            publisherPerm = new PublisherIdentityPermission(PermissionState.None);
            publisher = "null";
            publisherIndex++;
            return true;

        }

        X509Certificate cert = publisherCertificate[publisherIndex++];
        publisher = cert.ToString();
        try
        {
            publisherPerm = new PublisherIdentityPermission(cert);
            return true;
        }
        catch (Exception e)
        {
            Console.WriteLine("Cannot create PublisherIdentityPermission: " + publisher + " " + e);
            publisherPerm = new PublisherIdentityPermission(PermissionState.None);
            publisher = "null";
            return true;
        }

    }

} // End of PublisherGenerator.


import System.*;
import System.Security.*;
import System.Security.Permissions.*;
import System.Security.Cryptography.X509Certificates.*;
import System.IO.*;

/** @assembly CLSCompliant(true)
 */

public class PublisherIdentityDemo
{
    // IsSubsetOf determines whether the current permission is a subset 
    // of the specified permission.
    private boolean IsSubsetOfDemo() 
    {
        boolean retCode = true;
        String publisher1 = null;
        String publisher2 = null;
        PublisherIdentityPermission pubIdPerm1 = null; 
        PublisherIdentityPermission pubIdPerm2 = null;
        
        PublisherGenerator pubGen1 =  new PublisherGenerator();
        PublisherGenerator pubGen2 =  new PublisherGenerator();
        
        pubGen1.ResetIndex();
        while(pubGen1.CreatePublisher(pubIdPerm1, publisher1)) {
            if (pubIdPerm1 == null) {
                continue ;
            }
            pubGen2.ResetIndex();
            while(pubGen2.CreatePublisher(pubIdPerm2, publisher2)) {
                if (pubIdPerm2 == null) {
                    continue ;
                }
                
                try {
                    // Check for whether either of the publishers is null.
                    // An exception will be thrown if either is null.
                    if (publisher1 != "null" && publisher2 != "null") {
                        if ( pubIdPerm1.IsSubsetOf(pubIdPerm2)  ) {
                            Console.WriteLine((pubIdPerm1.get_Certificate().
                            GetName() + " is a subset of " 
                                + pubIdPerm2.get_Certificate().GetName() 
                                + "\n"));
                        }
                        else {
                            Console.WriteLine((pubIdPerm1.get_Certificate().
                            GetName() + " is not a subset of " 
                                + pubIdPerm2.get_Certificate().GetName() 
                                + "\n"));
                        }
                    }
                }
                catch(System.Exception exp){
                        Console.WriteLine(("An exception was thrown for " 
                            + publisher1 + " is a subset of " + publisher2 
                            + "\n."));
                        retCode = false;
                }
            }
        }
        return retCode ;
    } //IsSubsetOfDemo   

    // Union creates a new permission that is the union of the current 
    // permission and the specified permission.
    private boolean UnionDemo() 
    {
        boolean retCode = true;
        String publisher1 = null;
        String publisher2 = null;
        PublisherIdentityPermission pubIdPerm1 = null;
        PublisherIdentityPermission pubIdPerm2 = null;
        IPermission p3;
        
        PublisherGenerator pubGen1 =  new PublisherGenerator();
        PublisherGenerator pubGen2 =  new PublisherGenerator();
        
        pubGen1.ResetIndex();
        while(pubGen1.CreatePublisher(pubIdPerm1, publisher1)) {
                if (pubIdPerm1 == null | pubIdPerm1.get_Certificate()
                    == null) {
                    continue;
                }
                pubGen2.ResetIndex();
                while(pubGen2.CreatePublisher(pubIdPerm2, publisher2)) {
                if (pubIdPerm2 == null | pubIdPerm2.get_Certificate() 
                    == null) {
                    continue;
                }
                p3 = pubIdPerm1.Union(pubIdPerm2);
                
                if (p3 != null) {
                    Console.WriteLine(("The union of " 
                        + pubIdPerm1.get_Certificate().GetName() + " and " 
                        + pubIdPerm2.get_Certificate().GetName() + " = " 
                        + ((PublisherIdentityPermission)(p3)).get_Certificate().
                        GetName()));
                }
                else {
                    Console.WriteLine(("The union of " 
                        + pubIdPerm1.get_Certificate().GetName() 
                        + " and " + pubIdPerm2.get_Certificate().GetName() 
                        + " = null."));
                }
            }
        } 
        return retCode ;
    } //UnionDemo    

    // Intersect creates and returns a new permission that is the 
    // intersection of the current permission and the permission specified.
    private boolean IntersectDemo() 
    {
        boolean retCode = true;
        String publisher1 = null;
        String publisher2 = null;
        PublisherIdentityPermission pubIdPerm1 = null;
        PublisherIdentityPermission pubIdPerm2 = null;
        PublisherIdentityPermission p3;
        
        PublisherGenerator pubGen1 =  new PublisherGenerator();
        PublisherGenerator pubGen2 =  new PublisherGenerator();
        
        pubGen1.ResetIndex();
        while(pubGen1.CreatePublisher(pubIdPerm1, publisher1)) {
                if (pubIdPerm1 == null | pubIdPerm1.get_Certificate() 
                    == null) {
                    continue;
                }
                pubGen2.ResetIndex();
                while(pubGen2.CreatePublisher(pubIdPerm2, publisher2)) {
                if (pubIdPerm2 == null | pubIdPerm2.get_Certificate() 
                    == null) {
                    continue;
                }
                p3 =((PublisherIdentityPermission)(
                pubIdPerm1.Intersect(pubIdPerm2)));
                if (p3 != null && p3.get_Certificate() != null) {
                    Console.WriteLine(("The intersection of " 
                        + pubIdPerm1.get_Certificate().GetName() 
                        + " and " + pubIdPerm2.get_Certificate().GetName() 
                        + " = " + ((PublisherIdentityPermission)(p3)).
                        get_Certificate().GetName()));
                }
                else {
                    Console.WriteLine(("The intersection of " 
                        + pubIdPerm1.get_Certificate().GetName() 
                        + " and " + pubIdPerm2.get_Certificate().GetName() 
                        + " is null."));
                }
            }
        } 
        return retCode ;
    } //IntersectDemo    

    //Copy creates and returns an identical copy of the current permission.
    private boolean CopyDemo() 
    {
        boolean retCode = true;
        String publisher1 = null;
        PublisherIdentityPermission pubIdPerm1 = null;
        PublisherIdentityPermission pubIdPerm2 = null;
        
        PublisherGenerator pubGen1 =  new PublisherGenerator();
        PublisherGenerator pubGen2 =  new PublisherGenerator();
        
        pubGen1.ResetIndex();
        while(pubGen1.CreatePublisher(pubIdPerm1, publisher1)) {
            if (pubIdPerm1 == null) {
                continue ;
            }
            pubGen2.ResetIndex();
            try {
                pubIdPerm2 =((PublisherIdentityPermission)(pubIdPerm1.Copy()));
                if ( pubIdPerm2  != null  ) {
                    Console.WriteLine(("Result of copy = " + 
                    pubIdPerm2.ToString() + "\n"));
                }
                else {
                    Console.WriteLine("Result of copy is null. \n");
                }
            } 
            catch(System.Exception e) {
                Console.WriteLine(("Copy failed :" 
                    + pubIdPerm1.ToString() + e));
                continue ;
            }
        }
        return retCode ;
    } //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 boolean ToFromXmlDemo() 
    {
        boolean retCode = true;
        String publisher1 = null;
        PublisherIdentityPermission pubIdPerm1 = null;
        PublisherIdentityPermission pubIdPerm2 = null;
        
        PublisherGenerator pubGen1 =  new PublisherGenerator();
        PublisherGenerator pubGen2 =  new PublisherGenerator();
        
        pubGen1.ResetIndex();
        while(pubGen1.CreatePublisher(pubIdPerm1, publisher1)) {
            if (pubIdPerm1 == null) {
                continue ;
            }
            pubGen2.ResetIndex();
            try {
                pubIdPerm2 = 
                    new PublisherIdentityPermission(PermissionState.None);
                pubIdPerm2.FromXml(pubIdPerm1.ToXml());
                Console.WriteLine(("Result of ToFromXml = " 
                    + pubIdPerm2.ToString() + "\n"));
            }
            catch(System.Exception e) {
                Console.WriteLine(("ToFromXml failed :" 
                    + pubIdPerm1.ToString() + e));
                continue ;
            }
        }
        return retCode ;
    } //ToFromXmlDemo

    // Invoke all demos.
    public boolean RunDemo() 
    {
        boolean ret = true;
        boolean retTmp;
        
        // Call the IsSubsetOf demo.
        if (retTmp = IsSubsetOfDemo()) {
            Console.get_Out().WriteLine("IsSubsetOf demo " 
                + "completed successfully.");
        }
        else {
            Console.get_Out().WriteLine("IsSubsetOf demo failed.");
        }
        ret = retTmp && ret;
        Console.WriteLine("******************************" 
            + "******************************************");
        
        // Call the Union demo.
        if (retTmp = UnionDemo()) {
            Console.get_Out().WriteLine("Union demo completed successfully.");
        }
        else {
            Console.get_Out().WriteLine("Union demo failed.");
        }
        ret = retTmp && ret;
        Console.WriteLine("************************************" 
            + "************************************");
        
        // Call the Intersect demo.
        if (retTmp = IntersectDemo()) {
            Console.get_Out().WriteLine("Intersect demo " 
                + "completed successfully.");
        }
        else {
            Console.get_Out().WriteLine("Intersect demo failed.");
        }
        ret = retTmp && ret;
        Console.WriteLine("*****************************************" 
            + "*******************************");
        
        // Call the Copy demo.
        if (retTmp = CopyDemo()) {
            Console.get_Out().WriteLine("Copy demo completed successfully. ");
        }
        else {
            Console.get_Out().WriteLine("Copy demo failed.");
        }
        ret = retTmp && ret;
        Console.WriteLine("*********************************************" 
            + "***************************");
        
        // Call the ToFromXml demo
        if (retTmp = ToFromXmlDemo()) {
            Console.get_Out().WriteLine("ToFromXml demo " 
                + "completed successfully.");
        }
        else {
            Console.get_Out().WriteLine("ToFromXml demo failed.");
        }
        ret = retTmp && ret;
        Console.WriteLine("**********************************" 
            + "**************************************");
        return ret ;
    } //RunDemo

    // Test harness.
    public static void main(String[] args)
    {
        try {
            PublisherIdentityDemo democase =  new PublisherIdentityDemo();
            boolean ret = democase.RunDemo();
            if (ret) {
                Console.get_Out().WriteLine("The " 
                    + "PublisherIdentityPermission demo completed "
                    + "successfully.");
                Console.get_Out().WriteLine("Press the Enter key to exit.");
                String consoleInput = Console.ReadLine();
                System.Environment.set_ExitCode(100);
            }
            else {
                Console.get_Out().WriteLine("The " 
                    + "PublisherIdentityPermission demo failed.");
                Console.get_Out().WriteLine("Press the Enter key to exit.");
                String consoleInput = Console.ReadLine();
                System.Environment.set_ExitCode(101);
            }
        }
        catch(System.Exception e) {
            Console.get_Out().WriteLine("The " 
                + "PublisherIdentityPermission demo failed.");
            Console.WriteLine(e.ToString());
            Console.get_Out().WriteLine("Press the Enter key to exit.");
            String consoleInput = Console.ReadLine();
            System.Environment.set_ExitCode(101);
        }
    } 
} //PublisherIdentityDemo

// This class generates PublisherIdentityPermission objects.
class PublisherGenerator
{
    private X509Certificate publisherCertificate[] = new X509Certificate[2];
    private int publisherIndex = 0;
    public PublisherGenerator() 
    {
        try {
            FileStream fs1 =  new FileStream("MyCert1.cer", FileMode.Open);
            System.Byte certSBytes1[] = 
                new System.Byte[(int)(fs1.get_Length())];
            fs1.Read((ubyte[])certSBytes1, 0, (int)(fs1.get_Length()));
            publisherCertificate .set_Item( 0 , 
                new X509Certificate((ubyte[])certSBytes1) );
            fs1.Close();
            FileStream fs2 =  new FileStream("MyCert2.cer", FileMode.Open);
            System.Byte certSBytes2[] = 
                new System.Byte[(int)(fs2.get_Length())];
            fs2.Read((ubyte[])certSBytes2, 0, (int)(fs2.get_Length()));
            publisherCertificate .set_Item( 1 , 
                new X509Certificate((ubyte[])certSBytes2) );
            fs2.Close();
            ResetIndex();
        } 
        catch(System.Exception e) {
            Console.WriteLine(("Cannot create certificate : " + e));
            Console.get_Out().WriteLine("PublisherIdentityPermission " 
                + "demo failed.");
            System.Environment.set_ExitCode(101);
        }
    } //PublisherGenerator  

    public void ResetIndex()
    {
        publisherIndex = 0;
    } //ResetIndex

    // CreatePublisher creates a PublisherIdentityPermission.
    public boolean CreatePublisher(
        PublisherIdentityPermission publisherPerm, String publisher) 
    {
        if (publisherIndex >= publisherCertificate.length + 1) {
            publisherPerm = null;
            publisher = "null";
            return false ;
        }
        if (publisherIndex >= publisherCertificate.length) {
            publisherPerm = 
                new PublisherIdentityPermission(PermissionState.None);

            publisher = "null";
            publisherIndex++;
            return true ;
        }
        X509Certificate cert = publisherCertificate[publisherIndex++];
        publisher = cert.ToString();
        try {
            publisherPerm = new PublisherIdentityPermission(cert);
            return true ;
        }
        catch(System.Exception e) {
            Console.WriteLine(("Cannot create PublisherIdentityPermission: " 
                + publisher + " " + e));
            publisherPerm = 
                new PublisherIdentityPermission(PermissionState.None);
            publisher = "null";
            return true ;
        }
    } //CreatePublisher
} //PublisherGenerator 

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 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft