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 ref class PublisherIdentityPermission sealed : public CodeAccessPermission
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class PublisherIdentityPermission extends CodeAccessPermission
SerializableAttribute 
ComVisibleAttribute(true) 
public final class PublisherIdentityPermission extends CodeAccessPermission

The following code example demonstrates the behavior of the PublisherIdentityPermission methods. This sample is not intended to show the use of the permission. For an example of the use of PublisherIdentityPermission see PublisherIdentityPermission.

using namespace System::Runtime::InteropServices;
using namespace System;
using namespace System::Security;
using namespace System::Security::Permissions;
using namespace System::Security::Cryptography::X509Certificates;
using namespace System::IO;

// This class generates PublisherIdentityPermission objects.

[assembly:CLSCompliant(true)];
private ref class PublisherGenerator
{
private:
   array<X509Certificate^>^publisherCertificate;
   int publisherIndex;

public:
   PublisherGenerator()
   {
      publisherCertificate = gcnew array<X509Certificate^>(2);
      try
      {
         FileStream^ fs1 = gcnew FileStream( "MyCert1.cer",FileMode::Open );
         array<Byte>^certSBytes1 = gcnew array<Byte>((int)fs1->Length);
         fs1->Read( certSBytes1, 0, (int)fs1->Length );
         publisherCertificate[ 0 ] = gcnew X509Certificate( certSBytes1 );
         fs1->Close();
         FileStream^ fs2 = gcnew FileStream( "MyCert2.cer",FileMode::Open );
         array<Byte>^certSBytes2 = gcnew array<Byte>((int)fs2->Length);
         fs2->Read( certSBytes2, 0, (int)fs2->Length );
         publisherCertificate[ 1 ] = gcnew X509Certificate( certSBytes2 );
         fs2->Close();
         ResetIndex();
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Cannot create certificate : {0}", e );
         Console::WriteLine( "PublisherIdentityPermission demo failed." );
         System::Environment::ExitCode = 101;
      }

   }

   void ResetIndex()
   {
      publisherIndex = 0;
   }


   // CreatePublisher creates a PublisherIdentityPermission.
   bool CreatePublisher( [Out]interior_ptr<PublisherIdentityPermission^> publisherPerm, [Out]interior_ptr<String^> publisher )
   {
      if ( publisherIndex >= publisherCertificate->Length + 1 )
      {
          *publisherPerm = nullptr;
          *publisher = "null";
         return false;
      }

      if ( publisherIndex >= publisherCertificate->Length )
      {
         
          *publisherPerm = gcnew PublisherIdentityPermission( PermissionState::None );
         
          *publisher = "null";
         publisherIndex++;
         return true;
      }

      X509Certificate^ cert = publisherCertificate[ publisherIndex++ ];
       *publisher = cert->ToString();
      try
      {
          *publisherPerm = gcnew PublisherIdentityPermission( cert );
         return true;
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Cannot create PublisherIdentityPermission: {0} {1}",  *publisher, e );
          *publisherPerm = gcnew PublisherIdentityPermission( PermissionState::None );
          *publisher = "null";
         return true;
      }

   }

};


// End of PublisherGenerator.
// IsSubsetOf determines whether the current permission is a subset of the specified permission.
bool IsSubsetOfDemo()
{
   bool retCode = true;
   String^ publisher1;
   String^ publisher2;
   PublisherIdentityPermission^ pubIdPerm1;
   PublisherIdentityPermission^ pubIdPerm2;
   PublisherGenerator^ pubGen1 = gcnew PublisherGenerator;
   PublisherGenerator^ pubGen2 = gcnew PublisherGenerator;
   pubGen1->ResetIndex();
   while ( pubGen1->CreatePublisher(  &pubIdPerm1,  &publisher1 ) )
   {
      if ( pubIdPerm1 == nullptr )
            continue;

      pubGen2->ResetIndex();
      while ( pubGen2->CreatePublisher(  &pubIdPerm2,  &publisher2 ) )
      {
         if ( pubIdPerm2 == nullptr )
                  continue;
         try
         {
            
            // Check for whether either of the publishers is null.
            // An exception will be thrown if either is null.
            if (  !publisher1->Equals( "null" ) &&  !publisher2->Equals( "null" ) )
            {
               if ( pubIdPerm1->IsSubsetOf( pubIdPerm2 ) )
               {
                  Console::WriteLine( "{0} is a subset of {1}\n", pubIdPerm1->Certificate->GetName(), pubIdPerm2->Certificate->GetName() );
               }
               else
               {
                  Console::WriteLine( "{0} is not a subset of {1}\n", pubIdPerm1->Certificate->GetName(), pubIdPerm2->Certificate->GetName() );
               }
            }
         }
         catch ( Exception^ ) 
         {
            Console::WriteLine( "An exception was thrown for {0} is a subset of {1}\n.", publisher1, publisher2 );
            retCode = false;
         }

      }
   }

   return retCode;
}


// Union creates a new permission that is the union of the current permission and the specified permission.
bool UnionDemo()
{
   bool retCode = true;
   String^ publisher1;
   String^ publisher2;
   PublisherIdentityPermission^ pubIdPerm1;
   PublisherIdentityPermission^ pubIdPerm2;
   IPermission^ p3;
   PublisherGenerator^ pubGen1 = gcnew PublisherGenerator;
   PublisherGenerator^ pubGen2 = gcnew PublisherGenerator;
   pubGen1->ResetIndex();
   while ( pubGen1->CreatePublisher(  &pubIdPerm1,  &publisher1 ) )
   {
      if ( pubIdPerm1 == nullptr || pubIdPerm1->Certificate == nullptr )
            continue;

      pubGen2->ResetIndex();
      while ( pubGen2->CreatePublisher(  &pubIdPerm2,  &publisher2 ) )
      {
         if ( pubIdPerm2 == nullptr || pubIdPerm2->Certificate == nullptr )
                  continue;
         p3 = pubIdPerm1->Union( pubIdPerm2 );
         if ( p3 != nullptr )
         {
            Console::WriteLine( "The union of {0} and {1} = {2}", pubIdPerm1->Certificate->GetName(), pubIdPerm2->Certificate->GetName(), (dynamic_cast<PublisherIdentityPermission^>(p3))->Certificate->GetName() );
         }
         else
         {
            Console::WriteLine( "The union of {0} and {1} = null.", pubIdPerm1->Certificate->GetName(), pubIdPerm2->Certificate->GetName() );
         }
      }
   }

   return retCode;
}


// Intersect creates and returns a new permission that is the intersection of the 
// current permission and the permission specified.
bool IntersectDemo()
{
   bool retCode = true;
   String^ publisher1;
   String^ publisher2;
   PublisherIdentityPermission^ pubIdPerm1;
   PublisherIdentityPermission^ pubIdPerm2;
   PublisherIdentityPermission^ p3;
   PublisherGenerator^ pubGen1 = gcnew PublisherGenerator;
   PublisherGenerator^ pubGen2 = gcnew PublisherGenerator;
   pubGen1->ResetIndex();
   while ( pubGen1->CreatePublisher(  &pubIdPerm1,  &publisher1 ) )
   {
      if ( pubIdPerm1 == nullptr || pubIdPerm1->Certificate == nullptr )
            continue;

      pubGen2->ResetIndex();
      while ( pubGen2->CreatePublisher(  &pubIdPerm2,  &publisher2 ) )
      {
         if ( pubIdPerm2 == nullptr || pubIdPerm2->Certificate == nullptr )
                  continue;
         p3 = dynamic_cast<PublisherIdentityPermission^>(pubIdPerm1->Intersect( pubIdPerm2 ));
         if ( p3 != nullptr && p3->Certificate != nullptr )
         {
            Console::WriteLine( "The intersection of {0} and  {1} = {2}", pubIdPerm1->Certificate->GetName(), pubIdPerm2->Certificate->GetName(), (dynamic_cast<PublisherIdentityPermission^>(p3))->Certificate->GetName() );
         }
         else
         {
            Console::WriteLine( "The intersection of {0} and {1} is null.", pubIdPerm1->Certificate->GetName(), pubIdPerm2->Certificate->GetName() );
         }
      }
   }

   return retCode;
}


////Copy creates and returns an identical copy of the current permission.
bool CopyDemo()
{
   bool retCode = true;
   String^ publisher1;
   PublisherIdentityPermission^ pubIdPerm1;
   PublisherIdentityPermission^ pubIdPerm2;
   PublisherGenerator^ pubGen1 = gcnew PublisherGenerator;
   PublisherGenerator^ pubGen2 = gcnew PublisherGenerator;
   pubGen1->ResetIndex();
   while ( pubGen1->CreatePublisher(  &pubIdPerm1,  &publisher1 ) )
   {
      if ( pubIdPerm1 == nullptr )
            continue;

      pubGen2->ResetIndex();
      try
      {
         pubIdPerm2 = dynamic_cast<PublisherIdentityPermission^>(pubIdPerm1->Copy());
         if ( pubIdPerm2 != nullptr )
         {
            Console::WriteLine( "Result of copy = {0}\n", pubIdPerm2 );
         }
         else
         {
            Console::WriteLine( "Result of copy is null. \n" );
         }
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Copy failed :{0}{1}", pubIdPerm1, 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. 
bool ToFromXmlDemo()
{
   bool retCode = true;
   String^ publisher1;
   PublisherIdentityPermission^ pubIdPerm1;
   PublisherIdentityPermission^ pubIdPerm2;
   PublisherGenerator^ pubGen1 = gcnew PublisherGenerator;
   PublisherGenerator^ pubGen2 = gcnew PublisherGenerator;
   pubGen1->ResetIndex();
   while ( pubGen1->CreatePublisher(  &pubIdPerm1,  &publisher1 ) )
   {
      if ( pubIdPerm1 == nullptr )
            continue;

      pubGen2->ResetIndex();
      try
      {
         pubIdPerm2 = gcnew PublisherIdentityPermission( PermissionState::None );
         pubIdPerm2->FromXml( pubIdPerm1->ToXml() );
         Console::WriteLine( "Result of ToFromXml = {0}\n", pubIdPerm2 );
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "ToFromXml failed :{0}{1}", pubIdPerm1, e );
         continue;
      }

   }

   return retCode;
}


// Invoke all demos.
bool RunDemo()
{
   bool ret = true;
   bool retTmp;
   
   // Call the IsSubsetOf demo.
   if ( retTmp = IsSubsetOfDemo() )
      Console::WriteLine( "IsSubsetOf demo completed successfully." );
   else
      Console::WriteLine( "IsSubsetOf demo failed." );

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

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

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

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

   ret = retTmp && ret;
   Console::WriteLine( "************************************************************************" );
   return ret;
}


// Test harness.
int main()
{
   try
   {
      bool ret = RunDemo();
      if ( ret )
      {
         Console::WriteLine( "The PublisherIdentityPermission demo completed successfully." );
         Console::WriteLine( "Press the Enter key to exit." );
         Console::ReadLine();
         System::Environment::ExitCode = 100;
      }
      else
      {
         Console::WriteLine( "The PublisherIdentityPermission demo failed." );
         Console::WriteLine( "Press the Enter key to exit." );
         Console::ReadLine();
         System::Environment::ExitCode = 101;
      }
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "The PublisherIdentityPermission demo failed." );
      Console::WriteLine( e );
      Console::WriteLine( "Press the Enter key to exit." );
      Console::ReadLine();
      System::Environment::ExitCode = 101;
   }

}


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 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft