StrongNameIdentityPermissionとは? わかりやすく解説

StrongNameIdentityPermission クラス

厳密な名前の ID アクセス許可を定義します。このクラスは継承できません。

名前空間: System.Security.Permissions
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class
 StrongNameIdentityPermission
    Inherits CodeAccessPermission
Dim instance As StrongNameIdentityPermission
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public sealed class StrongNameIdentityPermission
 : CodeAccessPermission
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public ref class StrongNameIdentityPermission
 sealed : public CodeAccessPermission
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class StrongNameIdentityPermission
 extends CodeAccessPermission
SerializableAttribute 
ComVisibleAttribute(true) 
public final class StrongNameIdentityPermission
 extends CodeAccessPermission
解説解説

StrongNameIdentityPermission を使用して、呼び出し元のコードが特定の厳密に名前付けされたコード アセンブリ内にあるかどうかを確認することによって、バージョン管理と名前の保護を実現します。

厳密な名前 ID は、BLOB という暗号公開キーに基づいています。これは、オプションで固有のアセンブリの名前とバージョンを組み合わせることができます。このキーは一意の名前空間を定義しており、名前の定義はこのキーと対応する秘密キーによって署名されたアセンブリに存在する必要があるため、このキーによって名前が本物かどうかを厳密に検証できます。

厳密な名前キーの有効性は、必ずしも信頼関係またはキーに対して発行される証明書に依存しません。

メモメモ

StrongNameIdentityPermission に対するフル アクセス要求は、要求を満たす適切な証拠をスタック内のすべてのアセンブリが持っている場合に限り成功します。StrongNameIdentityPermissionAttribute を使用するリンク要求は、直前の呼び出し元が適切な証拠を持っている場合に限り成功します。

厳密な名前の詳細については、StrongName のトピックを参照してください。厳密な名前付きのアセンブリの詳細については、「厳密な名前付きアセンブリ」を参照してください。

StrongNameIdentityPermission クラスは、型のパブリック メンバにアクセスするための、厳密な名前の要件を定義する場合に使用します。StrongNameIdentityPermissionAttribute 属性を使用すると、厳密な名前の要件をアセンブリ レベルで定義できます。.NET Framework Version 2.0 では、InternalsVisibleToAttribute を使用して、アセンブリに含まれるパブリック以外のすべての型を、別のアセンブリに公開するように指定することもできます。詳細については、「フレンド アセンブリ (C# プログラミング ガイド)」を参照してください。

使用例使用例

StrongNameIdentityPermission クラスの使用方法を示すコード例を次に示します。この例は、クラス ライブラリの形式になっており、StrongNameIdentityPermissionAttribute 属性と、呼び出し元を特定の厳密な名前で署名するように要求する StrongNameIdentityPermission の両方に適用されます。

' The following commented code should be compiled as a console application
 to execute the 
' class library example.
'
'Imports System
'Imports System.Reflection
'Imports StrongNamedLibVb

'<Assembly: AssemblyVersion("1.0.0.0")> 
'<Assembly: AssemblyKeyFile("snKey.snk")> 
'Public Class StrongNameTest

'    ' Demonstrate the declarative and imperative forms of the StrongNameIdentityPermission.
'    Public Shared Sub Main()
'        Try
'            Dim signed As New Signed
'            signed.GetWindirImperative()
'            signed.GetWindirDeclarative()
'            Console.WriteLine("Called the signed library successfully.")
'        Catch e As Exception
'            Console.WriteLine(("Exception thrown in called assembly:
 " + e.Message))
'        End Try
'    End Sub 'Main
'End Class 'StrongNameTest
Imports System
Imports System.Security.Permissions
Imports System.Reflection
Imports Microsoft.VisualBasic

<assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyKeyFile("snKey.snk")> 
' Demand that the calling assembly has a specific strong name key.
' Use Sn.exe to generate the public key string used for the demand.
<StrongNameIdentityPermissionAttribute(SecurityAction.Demand, PublicKey:= _
        "0024000004800000940000000602000000240000525341310004000001000100ed92913322617b"
 + _
        "c45aae29aaaddd29c1af270797b200e698da08ceceaa546f911ad09ef0f6dbe4221fa30b8210c7"
 + _
        "6fe004702e540068e526273f35bd009d2026226d00ab72f4223b09e896c0f7af688fab2adb4242"
 + _
        "c2bfda793b5c2a259e0d6cd2bd09cbcc20305bd465c113e36b19854602dc53ce4766f568fc576d"
 + _
        "be3822b4")> _
Public Class Signed
    ' Read the environment windir variable.
    Public Sub GetWindirImperative()
        Try
            ' Use Sn.exe to generate the byte array for the public key.
            Dim b1 As Byte()
 = {0, 36, 0, 0, 4, 128, 0, 0, 148, 0, 0, 0, 6, 2, 0, 0, 0, _
                36, 0, 0, 82, 83, 65, 49, 0, 4, 0, 0, 1, 0, 1, 0, 237, 146, 145,
 51, 34, _
                97, 123, 196, 90, 174, 41, 170, 173, 221, 41, 193, 175, 39, 7, 151,
 178, 0, _
                230, 152, 218, 8, 206, 206, 170, 84, 111, 145, 26, 208, 158, 240,
 246, 219, _
                228, 34, 31, 163, 11, 130, 16, 199, 111, 224, 4, 112, 46, 84, 0,
 104, 229, _
                38, 39, 63, 53, 189, 0, 157, 32, 38, 34, 109, 0, 171, 114, 244, 34,
 59, 9, _
                232, 150, 192, 247, 175, 104, 143, 171, 42, 219, 66, 66, 194, 191,
 218, 121, _
                59, 92, 42, 37, 158, 13, 108, 210, 189, 9, 203, 204, 32, 48, 91,
 212, 101, _
                193, 19, 227, 107, 25, 133, 70, 2, 220, 83, 206, 71, 102, 245, 104,
 252, _
                87, 109, 190, 56, 34, 180}

            ' Specify the version of the calling assembly.
            Dim v1 As New
 Version("1.0.0.0")
            Dim blob As New
 StrongNamePublicKeyBlob(b1)
            If (ComparePublicKeys()) Then
                Console.WriteLine("Calling assembly has same key
 as this assembly.")
            Else
                Console.WriteLine("Calling assembly has different
 key than this assembly.")
            End If
            ' Create different permissions to exercise the set operations.
            Dim snPerm As New
 StrongNameIdentityPermission(blob, "StrongNamedExeVb",
 v1)
            snPerm.Demand()
            ' Return the location of the Windows directory that is found
 in 
            ' the windir environment variable.
            Console.WriteLine(Environment.GetEnvironmentVariable("windir"))
        Catch e As Exception
            Console.WriteLine(("Exception thrown in called assembly:
 " + e.Message))
        End Try
    End Sub 'GetWindir
    Public Sub GetWindirDeclarative()
        Try
            ' Return the location of the Windows directory that is found
 in 
            ' the windir environment variable.
            Console.WriteLine(Environment.GetEnvironmentVariable("windir"))
        Catch e As Exception
            Console.WriteLine(("Exception thrown in called assembly:
 " + e.Message))
        End Try
    End Sub 'GetWindir

    Public Shared Function
 ComparePublicKeys() As Boolean
        Try
            Dim callingAssembly As [Assembly]

            ' Create a target object.
            Dim Integer1 As New
 Int32
            Dim Type1 As Type

            ' Set the Type instance to the target class type.
            Type1 = Integer1.GetType()

            ' Create an instance of the assembly class to house the
 Integer type.  
            callingAssembly = [Assembly].GetAssembly(Integer1.GetType())

            ' Display the name of the calling assembly.
            Dim entryAssembly As [Assembly]
 = [Assembly].GetEntryAssembly()
            Dim mainAssembly As String
 = entryAssembly.FullName

            Console.WriteLine(("Calling assembly = "
 + entryAssembly.FullName))

            ' Get the name of the assembly being called (this assembly).
            Dim thisAssembly As String
 = [Assembly].GetCallingAssembly().FullName

            Console.WriteLine(("Called assembly="
 + thisAssembly))

            Dim tokenIndex1 As Integer
 = thisAssembly.LastIndexOf("PublicKeyToken")
            Dim tokenIndex2 As Integer
 = mainAssembly.LastIndexOf("PublicKeyToken")
            Dim testString1 As String
 = thisAssembly.Substring(tokenIndex1, 31)
            Dim testString2 As String
 = mainAssembly.Substring(tokenIndex2, 31)

            Return testString1.Equals(testString2)
        Catch
            Console.WriteLine("This is an unexpected exception")
            Throw
        End Try
    End Function 'ComparePublicKeys
End Class 'Signed
//The following commented code should be compiled as an console application
 to execute the
// class library example.
//
//using System;
//using System.Reflection;
//using SignedLib;
//[assembly: AssemblyVersion("1.0.0.0")]
//[assembly: AssemblyKeyFile("snKey.snk")]
//public class StrongNameTest
//{
//  // Demonstrate the declarative and imperative forms of the StrongNameIdentityPermission.
//  public static void Main()
//  {
//      try
//      {
//            Signed signedLib = new Signed();
//            signedLib.GetWindirImperative();
//            signedLib.GetWindirDeclarative();
//            Console.WriteLine( "Called the signed library assembly
 methods successfully.");
//      }
//      catch (Exception e)
//      {
//            Console.WriteLine( "Exception thrown in called assembly:
 " + e.Message);
//      }
//   }
//}
//
// Class library example to demonstrate StrongNameIdentityPermission
 and 
// StrongNameIdentityPermissionAttribute.
using System;
using System.Security.Permissions;
using System.Reflection;
[assembly: AssemblyVersion("1.0.*")]
[assembly :AssemblyKeyFile("snKey.snk")]
namespace SignedLib
{

    public class Signed
    {
        // Read the windir environment variable.
        public void GetWindirImperative()
        {
            try
            {
                // Use Sn.exe to generate the byte array for the public
 key.
                byte[] b1 = { 0, 36, 0, 0, 4, 128, 0, 0, 148, 0, 0, 0, 6, 2, 0, 0,
 0, 36, 
                    0, 0, 82, 83, 65, 49, 0, 4, 0, 0, 1, 0, 1, 0, 237, 146, 145,
 51, 34, 
                    97, 123, 196, 90, 174, 41, 170, 173, 221, 41, 193, 175, 39, 7,
 151, 
                    178, 0, 230, 152, 218, 8, 206, 206, 170, 84, 111, 145, 26, 208,
 158, 
                    240, 246, 219, 228, 34, 31, 163, 11, 130, 16, 199, 111, 224,
 4, 112, 
                    46, 84, 0, 104, 229, 38, 39, 63, 53, 189, 0, 157, 32, 38, 34,
 109, 0, 
                    171, 114, 244, 34, 59, 9, 232, 150, 192, 247, 175, 104, 143,
 171, 42, 
                    219, 66, 66, 194, 191, 218, 121, 59, 92, 42, 37, 158, 13, 108,
 210, 
                    189, 9, 203, 204, 32, 48, 91, 212, 101, 193, 19, 227, 107, 25,
 133, 
                    70, 2, 220, 83, 206, 71, 102, 245, 104, 252, 87, 109, 190, 56,
 34, 180 };

                // Specify the version of the calling assembly.
                Version v1 = new Version("1.0.0.0");
                StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob(b1);
                Console.WriteLine(ComparePublicKeys() ? "Calling assembly has
 same key as this assembly " : "Calling assembly has
 different key than this assembly");
                // Create different permissions to exercise the set
 operations.
                StrongNameIdentityPermission snPerm = new StrongNameIdentityPermission(blob,
 "StrongNamedExe", v1);
                snPerm.Demand();
                // Return the location of the Windows directory that
 is found in 
                // the windir environment variable.
                Console.WriteLine(Environment.GetEnvironmentVariable("windir"));
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception thrown in called
 assembly: " + e.Message);
            }
        }
    // Use an attribute to demand that the calling assembly has a specific
 strong name key.
    // Use Sn.exe to generate the public key string used for the demand.
    [StrongNameIdentityPermissionAttribute(SecurityAction.Demand, PublicKey = 
        "0024000004800000940000000602000000240000525341310004000001000100ed92913322617b"
 +
        "c45aae29aaaddd29c1af270797b200e698da08ceceaa546f911ad09ef0f6dbe4221fa30b8210c7"
 +
        "6fe004702e540068e526273f35bd009d2026226d00ab72f4223b09e896c0f7af688fab2adb4242"
 +
        "c2bfda793b5c2a259e0d6cd2bd09cbcc20305bd465c113e36b19854602dc53ce4766f568fc576d"
 +
        "be3822b4")]
        public void GetWindirDeclarative()
        {
            try
            {
                // Return the location of the Windows directory that
 is found in 
                // the windir environment variable.
                Console.WriteLine(Environment.GetEnvironmentVariable("windir"));
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception thrown in called
 assembly: " + e.Message);
            }
        }
        public static bool
 ComparePublicKeys()
        {
            try
            {
                Assembly callingAssembly;

                // Create a target object.
                Int32 integer1 = new Int32();
                Type type1;

                // Set the Type instance to the target class type.
                type1 = integer1.GetType();

                // Create an instance of the assembly class to house
 the Integer type.  
                callingAssembly = Assembly.GetAssembly(integer1.GetType());

                // Display the name of the calling assembly.
                Assembly entryAssembly = Assembly.GetEntryAssembly();
                string mainAssembly = entryAssembly.FullName;

                Console.WriteLine("Calling assembly = " + entryAssembly.FullName);

                // Get the name of the assembly being called (this assembly).
                string thisAssembly = Assembly.GetCallingAssembly().FullName;

                Console.WriteLine("Called assembly=" + thisAssembly);

                int tokenIndex1 = thisAssembly.LastIndexOf("PublicKeyToken");
                int tokenIndex2 = mainAssembly.LastIndexOf("PublicKeyToken");
                string testString1 = thisAssembly.Substring(tokenIndex1,
 31);
                string testString2 = mainAssembly.Substring(tokenIndex2,
 31);

                return testString1.Equals(testString2);
            }
            catch
            {
                Console.WriteLine("This is an unexpected exception");
                throw;
            }
        }
    }
}
//The following commented code should be compiled as an console application
 to execute the
// class library example.
//
//#using <mscorlib.dll>
//using namespace System;
//using namespace System::Reflection;
//using namespace SignedLib;
//[assembly: AssemblyVersion(S"1.0.0.0")]
//[assembly: AssemblyKeyFile(S"snKey.snk")];
//    // Demonstrate the declarative and imperative forms of the StrongNameIdentityPermission.
//int main()
//{
//    try
//    {
//        Signed* signedLib = new Signed();
//        signedLib->GetWindirImperative();
//        signedLib->GetWindirDeclarative();
//        Console::WriteLine( S"Called the signed library assembly
 methods successfully.");
//    }
//    catch (Exception* e)
//    {
//        Console::WriteLine( S"Exception thrown in called assembly:
 {0}", e->Message);
//    }
//}
//
// Class library example to demonstrate StrongNameIdentityPermission
 and 
// StrongNameIdentityPermissionAttribute.
using namespace System;
using namespace System::Security::Permissions;
using namespace System::Reflection;

[assembly:AssemblyVersion("1.0.*")];
[assembly:AssemblyKeyFile("snKey.snk")];
namespace SignedLib
{
   public ref class Signed
   {
   public:

      // Read the windir environment variable.
      void GetWindirImperative()
      {
         try
         {
            
            // Use Sn.exe to generate the byte array for the public
 key.
            array<Byte>^b1 = {0,36,0,0,4,128,0,0,148,0,0,0,6,2,0,0,0,36,0,0
,82,83,65,49,0,4,0,0,1,0,1,0,237,146,145,51,34,97,123,196,90,174,41,170,173,221
,41,193,175,39,7,151,178,0,230,152,218,8,206,206,170,84,111,145,26,208,158,240,246,219,228,34,31,163,11,130,16,199,111,224,4,112,46,84,0,104,229,38,39,63,53,189
,0,157,32,38,34,109,0,171,114,244,34,59,9,232,150,192,247,175,104,143,171,42,219,66,66,194,191,218,121,59,92,42,37,158,13,108,210,189,9,203,204,32,48,91,212,101,193,19,227,107,25,133,70,2,220,83,206,71,102,245,104,252,87,109,190,56,34,180};
            
            // Specify the version of the calling assembly.
            Version^ v1 = gcnew Version( "1.0.0.0" );
            StrongNamePublicKeyBlob^ blob = gcnew StrongNamePublicKeyBlob( b1 );
            Console::WriteLine( ComparePublicKeys() ? "Calling assembly has
 same key as this assembly " : "Calling assembly has
 different key than this assembly" );
            
            // Create different permissions to exercise the set operations.
            StrongNameIdentityPermission^ snPerm = gcnew StrongNameIdentityPermission(
 blob,"StrongNamedExe",v1 );
            snPerm->Demand();
            
            // Return the location of the Windows directory that is
 found in 
            // the windir environment variable.
            Console::WriteLine( Environment::GetEnvironmentVariable( "windir"
 ) );
         }
         catch ( Exception^ e ) 
         {
            Console::WriteLine( "Exception thrown in called
 assembly: {0}", e->Message );
         }

      }


      // Use an attribute to demand that the calling assembly has a specific
 strong name key.
      // Use Sn.exe to generate the public key string used for the demand.

      [StrongNameIdentityPermissionAttribute(SecurityAction::Demand,PublicKey=
      "0024000004800000940000000602000000240000525341310004000001000100ed92913322617b"
      "c45aae29aaaddd29c1af270797b200e698da08ceceaa546f911ad09ef0f6dbe4221fa30b8210c7"
      "activatede004702e540068e526273f35bd009d2026226d00ab72f4223b09e896c0f7af688fab2adb4242"
      "c2bfda793b5c2a259e0d6cd2bd09cbcc20305bd465c113e36b19854602dc53ce4766f568fc576d"
      "be3822b4")]
      void GetWindirDeclarative()
      {
         try
         {
            
            // Return the location of the Windows directory that is
 found in 
            // the windir environment variable.
            Console::WriteLine( Environment::GetEnvironmentVariable( "windir"
 ) );
         }
         catch ( Exception^ e ) 
         {
            Console::WriteLine( "Exception thrown in called
 assembly: {0}", e->Message );
         }

      }

      static bool ComparePublicKeys()
      {
         try
         {
            Assembly^ callingAssembly;
            
            // Create a target object.
            Int32 integer1 = Int32(  );
            Type^ type1;
            
            // Set the Type instance to the target class type.
            type1 = integer1.GetType();
            
            // Create an instance of the assembly class to house the
 Integer type.  
            callingAssembly = Assembly::GetAssembly( integer1.GetType() );
            
            // Display the name of the calling assembly.
            Assembly^ entryAssembly = Assembly::GetEntryAssembly();
            String^ mainAssembly = entryAssembly->FullName;
            Console::WriteLine( "Calling assembly = {0}", entryAssembly->FullName
 );
            
            // Get the name of the assembly being called (this assembly).
            String^ thisAssembly = Assembly::GetCallingAssembly()->FullName;
            Console::WriteLine( "Called assembly={0}", thisAssembly );
            int tokenIndex1 = thisAssembly->LastIndexOf( "PublicKeyToken"
 );
            int tokenIndex2 = mainAssembly->LastIndexOf( "PublicKeyToken"
 );
            String^ testString1 = thisAssembly->Substring( tokenIndex1, 31 );
            String^ testString2 = mainAssembly->Substring( tokenIndex2, 31 );
            return testString1->Equals( testString2 );
         }
         catch ( Exception^ ) 
         {
            Console::WriteLine( "This is an unexpected exception" );
            throw;
         }

      }

   };

}

package SignedLib ; 

//  The following commented code should be compiled as an console application
 
//  to execute the class library example.

//    import System .* ;
//    import System.Reflection .* ;
//    import SignedLib .* ;
//    /** @assembly AssemblyVersion("1.0.0.0")
//     */
//    /** @assembly AssemblyKeyFile("snKey.snk")
//     */
//    public class StrongNameTest
//    {
   
//        //Demonstrate the declarative and imperative forms of the
 
//        // StrongNameIdentityPermission.
//        public static void main(String[] args)
//        {
//            try {
//                Signed signedLib =  new Signed();
//                signedLib.GetWindirImperative();
//                signedLib.GetWindirDeclarative();
//                Console.WriteLine(("Called the signed library
 assembly " 
//                    + "methods successfully."));
//            }
//            catch(System.Exception e) {
//                Console.WriteLine(("Exception thrown in called
 assembly: " 
//                    + e.get_Message()));
//            }
//        } //main
//    } //StrongNameTest

// Class library example to demonstrate StrongNameIdentityPermission
 and 
// StrongNameIdentityPermissionAttribute.

import System.*;
import System.Security.Permissions.*;
import System.Reflection.*;

/** @assembly AssemblyVersion("1.0.*")
 */
/** @assembly AssemblyKeyFile("snKey.snk")
 */
public class Signed
{
    // Read the windir environment variable.
    public void GetWindirImperative()
    {
        try {
            // Use Sn.exe to generate the byte array for the public
 key.
            ubyte b1[] =  { 0, 36, 0, 0, 4, 128, 0, 0, 148, 0, 0, 0, 6, 2, 
                0, 0, 0, 36, 0, 0, 82, 83, 65, 49, 0, 4, 0, 0, 1, 0, 1, 0,
                237, 146, 145, 51, 34, 97, 123, 196, 90, 174, 41, 170, 173,
                221, 41, 193, 175, 39, 7, 151, 178, 0, 230, 152, 218, 8, 
                206, 206, 170, 84, 111, 145, 26, 208, 158, 240, 246, 219,
                228, 34, 31, 163, 11, 130, 16, 199, 111, 224, 4, 112, 46,
                84, 0, 104, 229, 38, 39, 63, 53, 189, 0, 157, 32, 38, 34,
                109, 0, 171, 114, 244, 34, 59, 9, 232, 150, 192, 247, 175,
                104, 143, 171, 42, 219, 66, 66, 194, 191, 218, 121, 59, 92,
                42, 37, 158, 13, 108, 210, 189, 9, 203, 204, 32, 48, 91, 
                212, 101, 193, 19, 227, 107, 25, 133, 70, 2, 220, 83, 206,
                71, 102, 245, 104, 252, 87, 109, 190, 56, 34, 180};

            // Specify the version of the calling assembly.
            Version v1 = new Version("1.0.0.0");
            StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob(b1);

            Console.WriteLine((ComparePublicKeys()) ? "Calling assembly "
 
                + "has same key as this assembly " :
 "Calling assembly has " 
                + "different key than this assembly");

            // Create different permissions to exercise the set operations.
            StrongNameIdentityPermission snPerm = 
                new StrongNameIdentityPermission(blob, "StrongNamedExe",
 v1);

            snPerm.Demand();

            // Return the location of the Windows directory that is
 found in 
            // the windir environment variable.
            Console.WriteLine(Environment.GetEnvironmentVariable("windir"));
        }
        catch (System.Exception e) {
            Console.WriteLine(("Exception thrown in called
 assembly: " 
                + e.get_Message()));
        }
    } //GetWindirImperative

    // Use an attribute to demand that the calling assembly has a 
    // specific strong name key.
    // Use Sn.exe to generate the public key string used for the demand.
    /** @attribute StrongNameIdentityPermissionAttribute(
        SecurityAction.Demand, PublicKey = 
        "0024000004800000940000000602000000240000525341310004000001000100ed"
 + 
        "92913322617b" + "c45aae29aaaddd29c1af270797b200e698da08ceceaa546f"
 + 
        "911ad09ef0f6dbe4221fa30b8210c7" + "6fe004702e540068e526273f35bd009d"
 + 
        "2026226d00ab72f4223b09e896c0f7af688fab2adb4242" + "c2bfda793b5c2a259"
 + 
        "e0d6cd2bd09cbcc20305bd465c113e36b19854602dc53ce4766f568fc576d"
 + 
        "be3822b4")
     */

    public void GetWindirDeclarative()
    {
        try {
            // Return the location of the Windows directory that is
 found in 
            // the windir environment variable.
            Console.WriteLine(Environment.GetEnvironmentVariable("windir"));
        }
        catch (System.Exception e) {
            Console.WriteLine(("Exception thrown in called
 assembly: " 
                + e.get_Message()));
        }
    } //GetWindirDeclarative

    public static boolean ComparePublicKeys()
 throws Exception
    {
        try {
            Assembly callingAssembly;

            // Create a target object.
            Int32 integer1 = new Int32();
            Type type1;

            // Set the Type instance to the target class type.
            type1 = integer1.GetType();

            // Create an instance of the assembly class to house the
 Integer 
            // type.  
            callingAssembly = Assembly.GetAssembly(integer1.GetType());

            // Display the name of the calling assembly.
            Assembly entryAssembly = Assembly.GetEntryAssembly();
            String mainAssembly = entryAssembly.get_FullName();

            Console.WriteLine(("Calling assembly = " 
                + entryAssembly.get_FullName()));

            // Get the name of the assembly being called (this assembly).
            String thisAssembly = Assembly.GetCallingAssembly().
                get_FullName();

            Console.WriteLine(("Called assembly=" + thisAssembly));

            int tokenIndex1 = thisAssembly.LastIndexOf("PublicKeyToken");
            int tokenIndex2 = mainAssembly.LastIndexOf("PublicKeyToken");
            String testString1 = thisAssembly.Substring(tokenIndex1, 31);
            String testString2 = mainAssembly.Substring(tokenIndex2, 31);

            return testString1.Equals(testString2);
        }
        catch (System.Exception exp) {
            Console.WriteLine("This is an unexpected exception");
            throw new Exception();
        }
    } //ComparePublicKeys
} //Signed

StrongNameIdentityPermission メソッドの動作を示すコード例を次に示します。この例では、メソッドの使用方法ではなく、メソッドの結果を示すことを目的としています。

Imports System
Imports System.Security
Imports System.Security.Permissions




Public Class StrongNameIdentityDemo
    ' Public key
    Private Shared b1 As
 Byte() =  {0, 36, 0, 0, 4, 128, 0, 0, 148, 0, 0, 0, 6, 2, 0,
 0, 0, 36, 0, 0, 82, 83, 65, 49, 0, 4, 0, 0, 1, 0, 1, 0, 237, 146, 145, 51, 34, 97, 123, 196, 90, 174, 41, 170, 173, 221, 41, 193, 175, 39, 7, 151, 178, 0, 230,
 152, 218, 8, 206, 206, 170, 84, 111, 145, 26, 208, 158, 240, 246, 219, 228, 34, 31, 163, 11, 130, 16, 199, 111, 224, 4, 112, 46, 84, 0, 104, 229, 38, 39, 63, 53, 189, 0, 157, 32, 38, 34, 109, 0, 171, 114, 244, 34, 59, 9, 232, 150, 192, 247, 175, 104, 143, 171, 42, 219, 66, 66, 194, 191, 218, 121, 59, 92, 42, 37, 158, 13,
 108, 210, 189, 9, 203, 204, 32, 48, 91, 212, 101, 193, 19, 227, 107, 25, 133, 70, 2, 220, 83, 206, 71, 102, 245, 104, 252, 87, 109, 190, 56, 34, 180}
    
    Private blob As New
 StrongNamePublicKeyBlob(b1)
    ' Use this version number.
    Private v1 As New Version("1.0.0.0")
    
    ' IsSubsetOf determines whether the current permission is a subset
 of the specified permission.
    Private Function IsSubsetOfDemo() As
 Boolean 
        
        Dim returnValue As Boolean
 = True
        
        Dim snIdPerm1, snIdPerm2 As StrongNameIdentityPermission
        
        snIdPerm1 = New StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*",
 New Version("1.0.0.0"))
        snIdPerm2 = New StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.MyFile",
 New Version("1.0.0.0"))
        
        If snIdPerm1.IsSubsetOf(snIdPerm2) Then
            
            Console.WriteLine("MyCompany.MyDepartment.* is a subset
 " + "of MyCompany.MyDepartment.MyFile "
 + vbLf)
        Else
            Console.WriteLine("MyCompany.MyDepartment.*"
 + " is not a subset of MyCompany.MyDepartment.MyFile "
 + vbLf)
        End If
        
        Return returnValue
    
    End Function 'IsSubsetOfDemo
    
    ' Union creates a new permission that is the union of the current
 permission and the specified permission.
    Private Function UnionDemo() As
 Boolean 
        
        Dim returnValue As Boolean
 = True
        
        Dim snIdPerm1, snIdPerm2 As StrongNameIdentityPermission
        Dim snIdPerm3 As IPermission
        
        snIdPerm1 = New StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*",
 New Version("1.0.0.0"))
        snIdPerm2 = New StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.MyFile",
 New Version("1.0.0.0"))
        
        snIdPerm3 = CType(snIdPerm1.Union(snIdPerm2), StrongNameIdentityPermission)
        
        Try
            Console.WriteLine("The union of MyCompany.MyDepartment.*"
 + "and MyCompany.MyDepartment.MyFile is " + CType(snIdPerm3,
 StrongNameIdentityPermission).Name.ToString())
        Catch e As Exception
            Console.WriteLine("An expected exception was thrown:
 " + e.Message)
        End Try
        
        
        Return returnValue
    
    End Function 'UnionDemo
     
    ' Intersect creates and returns a new permission that is the intersection
 of the current
    ' permission and the permission specified.
    Private Function IntersectDemo() As
 Boolean 
        
        Dim returnValue As Boolean
 = True
        
        Dim snIdPerm1, snIdPerm2, snIdPerm3 As
 StrongNameIdentityPermission
        
        snIdPerm1 = New StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*",
 New Version("1.0.0.0"))
        snIdPerm2 = New StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.MyFile",
 New Version("1.0.0.0"))
        
        Try
            
            snIdPerm3 = CType(snIdPerm1.Intersect(snIdPerm2), StrongNameIdentityPermission)
            
            Console.WriteLine("The intersection of MyCompany.MyDepartment.*"
 + "MyCompany.MyDepartment.MyFile is " + CType(snIdPerm3,
 StrongNameIdentityPermission).Name.ToString())
        
        Catch e As Exception
            Console.WriteLine("An exception was thrown: "
 + e.ToString())
            returnValue = False
        End Try
        
        Return returnValue
    
    End Function 'IntersectDemo
     
    'Copy creates and returns an identical copy of the current permission.
    Private Function CopyDemo() As
 Boolean 
        Dim returnValue As Boolean
 = True
        
        Dim snIdPerm1, snIdPerm2 As StrongNameIdentityPermission
        
        snIdPerm1 = New StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*",
 New Version("1.0.0.0"))
        snIdPerm2 = New StrongNameIdentityPermission(PermissionState.None)
        snIdPerm2 = CType(snIdPerm1.Copy(), StrongNameIdentityPermission)
        Console.WriteLine("Result of copy = " + snIdPerm2.ToString()
 + vbLf)
        
        Return returnValue
    
    End Function '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 Function ToFromXmlDemo() As
 Boolean 
        
        Dim returnValue As Boolean
 = True
        
        Dim snIdPerm1, snIdPerm2 As StrongNameIdentityPermission
        
        snIdPerm1 = New StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*",
 New Version("1.0.0.0"))
        snIdPerm2 = New StrongNameIdentityPermission(PermissionState.None)
        snIdPerm2.FromXml(snIdPerm1.ToXml())
        Console.WriteLine("Result of ToFromXml = "
 + snIdPerm2.ToString() + vbLf)
        
        Return returnValue
    
    End Function 'ToFromXmlDemo
     
    ' Invoke all demos.
    Public Function runDemo() As
 Boolean

        Dim ret As Boolean
 = True
        Dim retTmp As Boolean
        ' Call the IsSubsetOf demo.
        retTmp = IsSubsetOfDemo()
        If retTmp Then
            Console.Out.WriteLine("IsSubsetOf demo completed successfully.")
        Else
            Console.Out.WriteLine("IsSubsetOf demo failed.")
        End If
        ret = retTmp AndAlso ret

        ' Call the Union demo.
        retTmp = UnionDemo()
        If retTmp Then
            Console.Out.WriteLine("Union demo completed successfully.")
        Else
            Console.Out.WriteLine("Union demo failed.")
        End If
        ret = retTmp AndAlso ret

        ' Call the Intersect demo.
        retTmp = IntersectDemo()
        If retTmp Then
            Console.Out.WriteLine("Intersect demo completed successfully.")
        Else
            Console.Out.WriteLine("Intersect demo failed.")
        End If
        ret = retTmp AndAlso ret


        ' Call the Copy demo.
        retTmp = CopyDemo()
        If retTmp Then
            Console.Out.WriteLine("Copy demo completed successfully")
        Else
            Console.Out.WriteLine("Copy demo failed.")
        End If
        ret = retTmp AndAlso ret

        ' Call the ToFromXml demo.    
        retTmp = ToFromXmlDemo()
        If retTmp Then
            Console.Out.WriteLine("ToFromXml demo completed successfully")
        Else
            Console.Out.WriteLine("ToFromXml demo failed.")
        End If
        ret = retTmp AndAlso ret

        Console.WriteLine("********************************************************"
 + ControlChars.Lf)


        Return ret
    End Function 'runDemo


    ' Test harness.
    Public Overloads Shared
 Sub Main(ByVal args() As
 [String])
        Try
            Dim democase As New
 StrongNameIdentityDemo()
            Dim ret As Boolean
 = democase.runDemo()
            If ret Then
                Console.Out.WriteLine("StrongNameIdentity demo
 completed successfully.")
                Console.Out.WriteLine("Press the Enter key to
 exit.")
                Dim consoleInput As String
 = Console.ReadLine()
                System.Environment.ExitCode = 100
            Else
                Console.Out.WriteLine("StrongNameIdentity demo
 failed.")
                Console.Out.WriteLine("Press the Enter key to
 exit.")
                Dim consoleInput As String
 = Console.ReadLine()
                System.Environment.ExitCode = 101
            End If
        Catch e As Exception
            Console.Out.WriteLine("StrongNameIdentity demo failed.")
            Console.WriteLine(e.ToString())
            Console.Out.WriteLine("Press the Enter key to exit.")
            Dim consoleInput As String
 = Console.ReadLine()
            System.Environment.ExitCode = 101
        End Try
    End Sub 'Main
End Class 'StrongNameIdentityDemo

using System;
using System.Security;
using System.Security.Permissions;


public class StrongNameIdentityDemo
{
    // Public key
    static byte[] b1 = { 0, 36, 0, 0, 4, 128, 0, 0, 148, 0, 0,
 0, 6, 2, 0, 0, 0, 36, 0, 0,
82, 83, 65, 49, 0, 4, 0, 0, 1, 0, 1, 0, 237, 146, 145, 51, 34,
97, 123, 196, 90, 174, 41, 170, 173, 221, 41, 193, 175, 39, 7,
151, 178, 0, 230, 152, 218, 8, 206, 206, 170,84, 111, 145, 26,
208, 158, 240, 246, 219, 228, 34, 31, 163, 11, 130, 16, 199, 111,
224, 4, 112, 46, 84, 0, 104, 229, 38, 39, 63, 53, 189, 0, 157,
32, 38, 34, 109, 0, 171, 114, 244, 34, 59, 9, 232, 150, 192, 247,
175, 104, 143, 171, 42, 219, 66, 66, 194, 191, 218, 121, 59, 92,
42, 37, 158, 13, 108, 210, 189, 9, 203, 204, 32, 48, 91, 212, 101,
193, 19, 227, 107, 25, 133, 70, 2, 220, 83, 206, 71, 102, 245, 104,
252, 87, 109, 190, 56, 34, 180};

    StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob(b1);
    // Use this version number.
    Version v1 = new Version("1.0.0.0");
    // IsSubsetOf determines whether the current permission is a subset
 of the specified permission.
    private bool IsSubsetOfDemo()
    {

        bool returnValue = true;

        StrongNameIdentityPermission snIdPerm1, snIdPerm2;

        snIdPerm1 = new StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*",
 new Version("1.0.0.0"));
        snIdPerm2 = new StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.MyFile",
 new Version("1.0.0.0"));

        if (snIdPerm1.IsSubsetOf(snIdPerm2))
        {

            Console.WriteLine("MyCompany.MyDepartment.* is a subset " +
            "of MyCompany.MyDepartment.MyFile \n");
        }
        else
        {
            Console.WriteLine("MyCompany.MyDepartment.*" +
            " is not a subset of MyCompany.MyDepartment.MyFile \n");
        }

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

        bool returnValue = true;

        StrongNameIdentityPermission snIdPerm1, snIdPerm2;
        IPermission snIdPerm3;

        snIdPerm1 = new StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*",
 new Version("1.0.0.0"));
        snIdPerm2 = new StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.MyFile",
 new Version("1.0.0.0"));

        snIdPerm3 = (StrongNameIdentityPermission)snIdPerm1.Union(snIdPerm2);

        try
        {
            Console.WriteLine("The union of MyCompany.MyDepartment.*" +
            "and MyCompany.MyDepartment.MyFile is " +
            ((StrongNameIdentityPermission)snIdPerm3).Name.ToString());
        }
        catch (Exception e)
        {
            Console.WriteLine("An expected exception was thrown: " + e.Message);
        }


        return returnValue;

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

        bool returnValue = true;

        StrongNameIdentityPermission snIdPerm1, snIdPerm2, snIdPerm3;

        snIdPerm1 = new StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*",
 new Version("1.0.0.0"));
        snIdPerm2 = new StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.MyFile",
 new Version("1.0.0.0"));

        try
        {

            snIdPerm3 = (StrongNameIdentityPermission)snIdPerm1.Intersect(snIdPerm2);

            Console.WriteLine("The intersection of MyCompany.MyDepartment.*"
            + "MyCompany.MyDepartment.MyFile is "
            + ((StrongNameIdentityPermission)snIdPerm3).Name.ToString());

        }
        catch (Exception e)
        {
            Console.WriteLine("An exception was thrown: " + e);
            returnValue = false;
        }

        return returnValue;

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

        StrongNameIdentityPermission snIdPerm1, snIdPerm2;

        snIdPerm1 = new StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*",
 new Version("1.0.0.0"));
        snIdPerm2 = new StrongNameIdentityPermission(PermissionState.None);

        snIdPerm2 = (StrongNameIdentityPermission)snIdPerm1.Copy();
        Console.WriteLine("Result of copy = " + snIdPerm2.ToString() +
 "\n");

        return returnValue;
    }
    // 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 returnValue = true;

        StrongNameIdentityPermission snIdPerm1, snIdPerm2;

        snIdPerm1 = new StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*",
 new Version("1.0.0.0"));    
        snIdPerm2 = new StrongNameIdentityPermission(PermissionState.None);
        snIdPerm2.FromXml(snIdPerm1.ToXml());
        Console.WriteLine("Result of ToFromXml = " + snIdPerm2.ToString()
 + "\n");

        return returnValue;

    }
    // 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;

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

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


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

        // 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("********************************************************\n");


        return (ret);






    }
    // Test harness.
    public static void Main(String[]
 args)
    {
        try
        {
            StrongNameIdentityDemo democase = new StrongNameIdentityDemo();
            bool ret = democase.RunDemo();
            if (ret)
            {
                Console.Out.WriteLine("StrongNameIdentity demo completed successfully.");
                Console.Out.WriteLine("Press the Enter key to exit.");
                string consoleInput = Console.ReadLine();
                System.Environment.ExitCode = 100;
            }
            else
            {
                Console.Out.WriteLine("StrongNameIdentity 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("StrongNameIdentity demo failed.");
            Console.WriteLine(e.ToString());
            Console.Out.WriteLine("Press the Enter key to exit.");
            string consoleInput = Console.ReadLine();
            System.Environment.ExitCode = 101;
        }
        // Catch non-CLSCompliant exceptions.
        catch
        {
            Console.WriteLine("An unexpected non-CLSCompliant exception was
 thrown.");
        }
    }
}

using namespace System;
using namespace System::Security;
using namespace System::Security::Permissions;
using namespace System::Runtime::InteropServices;

// This class generates StrongNameIdentityPermission objects.

[assembly:CLSCompliant(true)];

public ref class StrongNameIdentityDemo
{
private:
    // Public key
    static array<Byte>^b1 = {0,36,0,0,4,128,0,0,148,0,0
,0,6,2,0,0,0,36,0,0,82,83,65,49,0,4,0,0,1,0,1,0,237,146,145,51,34,97,123,196,90
,174,41,170,173,221,41,193,175,39,7,151,178,0,230,152,218,8,206,206,170,84,111,145,26,208,158,240,246,219,228,34,31,163,11,130,16,199,111,224,4,112,46,84,0,104
,229,38,39,63,53,189,0,157,32,38,34,109,0,171,114,244,34,59,9,232,150,192,247,175,104,143,171,42,219,66,66,194,191,218,121,59,92,42,37,158,13,108,210,189,9,203,204,32,48,91,212,101,193,19,227,107,25,133,70,2,220,83,206,71,102,245,104,252,87,109,190,56,34,180};
    static StrongNamePublicKeyBlob^ blob = gcnew StrongNamePublicKeyBlob(
 b1 );

    // Use this version number.
    static Version^ v1 = gcnew Version( "1.0.0.0" );

    // IsSubsetOf determines whether the current permission is a subset
 of the specified permission.
    bool IsSubsetOfDemo()
    {
        bool returnValue = true;

        StrongNameIdentityPermission^ snIdPerm1;
        StrongNameIdentityPermission^ snIdPerm2;

        snIdPerm1 = gcnew StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*",
 gcnew Version("1.0.0.0"));
        snIdPerm2 = gcnew StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.MyFile",
 gcnew Version("1.0.0.0"));

        if (snIdPerm1->IsSubsetOf(snIdPerm2))
        {

            Console::WriteLine("MyCompany.MyDepartment.* is a subset "
 +
                "of MyCompany.MyDepartment.MyFile \n");
        }
        else
        {
            Console::WriteLine("MyCompany.MyDepartment.*" +
                " is not a subset of MyCompany.MyDepartment.MyFile \n");
        }

        return returnValue;
    }


    // Union creates a new permission that is the union of the current
 permission and the specified permission.
    bool UnionDemo()
    {
        bool returnValue = true;
        StrongNameIdentityPermission^ snIdPerm1;
        StrongNameIdentityPermission^ snIdPerm2;
        IPermission^ snIdPerm3;
        snIdPerm1 = gcnew StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*",
 gcnew Version("1.0.0.0"));
        snIdPerm2 = gcnew StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.MyFile",
 gcnew Version("1.0.0.0"));
        snIdPerm3 = dynamic_cast<StrongNameIdentityPermission^>(snIdPerm1->Union(
 snIdPerm2 ));
        snIdPerm3 = snIdPerm1->Union( snIdPerm2 );

        try
        {
            Console::WriteLine("The union of MyCompany.MyDepartment.*"
 +
                "and MyCompany.MyDepartment.MyFile is " +
                (dynamic_cast<StrongNameIdentityPermission^>(snIdPerm3))->Name);
 
        }
        catch (Exception^ e)
        {
            Console::WriteLine("An expected exception was thrown: " + e->Message);
        }


        return returnValue;
    }


    // Intersect creates and returns a new permission that is the intersection
 of the current
    // permission and the permission specified.
    bool IntersectDemo()
    {
        bool returnValue = true;
        StrongNameIdentityPermission^ snIdPerm1;
        StrongNameIdentityPermission^ snIdPerm2;
        StrongNameIdentityPermission^ snIdPerm3;
        snIdPerm1 = gcnew StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*",
 gcnew Version("1.0.0.0"));
        snIdPerm2 = gcnew StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.MyFile",
 gcnew Version("1.0.0.0"));

        try
        {

            snIdPerm3 = dynamic_cast<StrongNameIdentityPermission^>(snIdPerm1->Intersect(snIdPerm2));

            Console::WriteLine("The intersection of MyCompany.MyDepartment.*"
 +
                "and MyCompany.MyDepartment.MyFile is " +
                (dynamic_cast<StrongNameIdentityPermission^>(snIdPerm3))->Name);
        }
        catch (Exception^ e)
        {
            Console::WriteLine("An exception was thrown: " + e);
            returnValue = false;
        }

        return returnValue;

    }


    //Copy creates and returns an identical copy of the current permission.
    bool CopyDemo()
    {
        bool returnValue = true;
        StrongNameIdentityPermission^ snIdPerm1;
        StrongNameIdentityPermission^ snIdPerm2;
        snIdPerm1 = gcnew StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*",
 gcnew Version("1.0.0.0"));
        snIdPerm2 = gcnew StrongNameIdentityPermission(PermissionState::None);

        snIdPerm2 = dynamic_cast<StrongNameIdentityPermission^>(snIdPerm1->Copy());
        Console::WriteLine("Result of copy = " + snIdPerm2->ToString()
 + "\n");

        return returnValue;
    }


    // 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 returnValue = true;
        StrongNameIdentityPermission^ snIdPerm1;
        StrongNameIdentityPermission^ snIdPerm2;
        snIdPerm1 = gcnew StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*",
 gcnew Version("1.0.0.0"));    
        snIdPerm2 = gcnew StrongNameIdentityPermission(PermissionState::None);
        snIdPerm2->FromXml(snIdPerm1->ToXml());
        Console::WriteLine("Result of ToFromXml = " + snIdPerm2->ToString()
 + "\n");

        return returnValue;
    }


public:

    // 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;

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

        ret = retTmp && ret;

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

        ret = retTmp && ret;

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

        ret = retTmp && ret;

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

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

};


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

}

継承階層継承階層
System.Object
   System.Security.CodeAccessPermission
    System.Security.Permissions.StrongNameIdentityPermission
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
StrongNameIdentityPermission メンバ
System.Security.Permissions 名前空間
StrongNameIdentityPermission クラス
StrongNamePublicKeyBlob
StrongName
StrongNameMembershipCondition
その他の技術情報
アクセス許可
アクセス許可の要求
厳密な名前付きアセンブリ

StrongNameIdentityPermission コンストラクタ (StrongNamePublicKeyBlob, String, Version)

指定した厳密な名前 ID を使用して、StrongNameIdentityPermission クラスの新しいインスタンスを初期化します。

名前空間: System.Security.Permissions
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    blob As StrongNamePublicKeyBlob, _
    name As String, _
    version As Version _
)
Dim blob As StrongNamePublicKeyBlob
Dim name As String
Dim version As Version

Dim instance As New StrongNameIdentityPermission(blob,
 name, version)
public StrongNameIdentityPermission (
    StrongNamePublicKeyBlob blob,
    string name,
    Version version
)
public:
StrongNameIdentityPermission (
    StrongNamePublicKeyBlob^ blob, 
    String^ name, 
    Version^ version
)
public StrongNameIdentityPermission (
    StrongNamePublicKeyBlob blob, 
    String name, 
    Version version
)
public function StrongNameIdentityPermission
 (
    blob : StrongNamePublicKeyBlob, 
    name : String, 
    version : Version
)

パラメータ

blob

厳密な名前 ID 名前空間を定義する公開キー。

name

厳密な名前 ID の単純な名前の部分。これは、アセンブリの名前に対応します。

version

ID のバージョン番号。

例外例外
例外の種類条件

ArgumentNullException

blob パラメータが null 参照 (Visual Basic では Nothing) です。

ArgumentException

name パラメータが空の文字列 ("") です。

解説解説
使用例使用例

StrongNameIdentityPermission コンストラクタを使用する方法を次のコード例に示します。

snIdPerm1 = New StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*",
 New Version("1.0.0.0"))
snIdPerm1 = new StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*",
 new Version("1.0.0.0"));
snIdPerm1 = gcnew StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*",
 gcnew Version("1.0.0.0"));
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
StrongNameIdentityPermission クラス
StrongNameIdentityPermission メンバ
System.Security.Permissions 名前空間

StrongNameIdentityPermission コンストラクタ (PermissionState)

PermissionState を指定して、StrongNameIdentityPermission クラスの新しいインスタンスを初期化します。

名前空間: System.Security.Permissions
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    state As PermissionState _
)
Dim state As PermissionState

Dim instance As New StrongNameIdentityPermission(state)
public StrongNameIdentityPermission (
    PermissionState state
)
public:
StrongNameIdentityPermission (
    PermissionState state
)
public StrongNameIdentityPermission (
    PermissionState state
)
public function StrongNameIdentityPermission
 (
    state : PermissionState
)

パラメータ

state

PermissionState 値の 1 つ。

例外例外
例外の種類条件

ArgumentException

state パラメータが、PermissionState の有効値ではありません。

解説解説
使用例使用例

StrongNameIdentityPermission コンストラクタを使用する方法を次のコード例に示します。

snIdPerm2 = New StrongNameIdentityPermission(PermissionState.None)
snIdPerm2 = new StrongNameIdentityPermission(PermissionState.None);
snIdPerm2 = gcnew StrongNameIdentityPermission(PermissionState::None);
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
StrongNameIdentityPermission クラス
StrongNameIdentityPermission メンバ
System.Security.Permissions 名前空間

StrongNameIdentityPermission コンストラクタ

StrongNameIdentityPermission クラスの新しいインスタンスを初期化します。
オーバーロードの一覧オーバーロードの一覧

名前 説明
StrongNameIdentityPermission (PermissionState) PermissionState を指定して、StrongNameIdentityPermission クラスの新しいインスタンスを初期化します。
StrongNameIdentityPermission (StrongNamePublicKeyBlob, String, Version) 指定した厳密な名前 ID を使用して、StrongNameIdentityPermission クラスの新しいインスタンスを初期化します。
参照参照

関連項目

StrongNameIdentityPermission クラス
StrongNameIdentityPermission メンバ
System.Security.Permissions 名前空間

StrongNameIdentityPermission プロパティ


パブリック プロパティパブリック プロパティ

参照参照

関連項目

StrongNameIdentityPermission クラス
System.Security.Permissions 名前空間
StrongNameIdentityPermission クラス
StrongNamePublicKeyBlob
StrongName
StrongNameMembershipCondition

その他の技術情報

アクセス許可
アクセス許可の要求
厳密な名前付きアセンブリ

StrongNameIdentityPermission メソッド


パブリック メソッドパブリック メソッド

  名前 説明
パブリック メソッド Assert  アクセス許可要求によって保護されているリソースへのアクセス許可が、スタックの上位にある呼び出し元に与えられていない場合でも、呼び出し元コードが、このメソッドを呼び出すコードを通じてリソースにアクセスできるように宣言します。Assert を使用すると、セキュリティ上の問題が発生することがあります。 ( CodeAccessPermission から継承されます。)
パブリック メソッド Copy オーバーライドされます。 現在のアクセス許可のコピーを作成して返します。
パブリック メソッド Demand  コール スタック内の上位にあるすべての呼び出し元に、現在のインスタンスによって指定されているアクセス許可が与えられていない場合は、実行時に SecurityException を強制します。 ( CodeAccessPermission から継承されます。)
パブリック メソッド Deny  コール スタックの上位の呼び出し元が、このメソッドを呼び出すコードを使用して、現在のインスタンスによって指定されるリソースにアクセスできないようにします。 ( CodeAccessPermission から継承されます。)
パブリック メソッド Equals  オーバーロードされます。 ( CodeAccessPermission から継承されます。)
パブリック メソッド FromXml オーバーライドされます。 XML エンコーディングから、指定した状態のアクセス許可を再構築します。
パブリック メソッド GetHashCode  ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適した CodeAccessPermission オブジェクトのハッシュ コードを取得します。 ( CodeAccessPermission から継承されます。)
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 ( Object から継承されます。)
パブリック メソッド Intersect オーバーライドされます。 現在のアクセス許可と指定したアクセス許可の積集合を表すアクセス許可を作成して返します。
パブリック メソッド IsSubsetOf オーバーライドされます。 現在のアクセス許可が、指定したアクセス許可のサブセットかどうかを判断します。
パブリック メソッド PermitOnly  コール スタックの上位の呼び出し元が、このメソッドを呼び出すコードを使用して、現在のインスタンスによって指定されるリソース以外のすべてのリソースにアクセスできないようにします。 ( CodeAccessPermission から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。)
パブリック メソッド RevertAll  現在のフレームに対する以前のオーバーライドをすべて削除し、無効にします。 ( CodeAccessPermission から継承されます。)
パブリック メソッド RevertAssert  現在のフレームに対する以前の Assert をすべて削除し、無効にします。 ( CodeAccessPermission から継承されます。)
パブリック メソッド RevertDeny  現在のフレームに対する以前の Deny をすべて削除し、無効にします。 ( CodeAccessPermission から継承されます。)
パブリック メソッド RevertPermitOnly  現在のフレームに対する以前の PermitOnly をすべて削除し、無効にします。 ( CodeAccessPermission から継承されます。)
パブリック メソッド ToString  現在のアクセス許可オブジェクトの文字列形式を作成して返します。 ( CodeAccessPermission から継承されます。)
パブリック メソッド ToXml オーバーライドされます。 アクセス許可とその現在の状態を表す XML エンコーディングを作成します。
パブリック メソッド Union オーバーライドされます。 現在のアクセス許可と指定したアクセス許可の和集合を表すアクセス許可を作成します。
参照参照

関連項目

StrongNameIdentityPermission クラス
System.Security.Permissions 名前空間
StrongNameIdentityPermission クラス
StrongNamePublicKeyBlob
StrongName
StrongNameMembershipCondition

その他の技術情報

アクセス許可
アクセス許可の要求
厳密な名前付きアセンブリ

StrongNameIdentityPermission メンバ

厳密な名前の ID アクセス許可を定義します。このクラスは継承できません。

StrongNameIdentityPermission データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド StrongNameIdentityPermission オーバーロードされます。 StrongNameIdentityPermission クラスの新しいインスタンスを初期化します。
パブリック プロパティパブリック プロパティ
パブリック メソッドパブリック メソッド
  名前 説明
パブリック メソッド Assert  アクセス許可要求によって保護されているリソースへのアクセス許可が、スタックの上位にある呼び出し元に与えられていない場合でも、呼び出し元コードが、このメソッドを呼び出すコードを通じてリソースにアクセスできるように宣言します。Assert を使用すると、セキュリティ上の問題が発生することがあります。 (CodeAccessPermission から継承されます。)
パブリック メソッド Copy オーバーライドされます。 現在のアクセス許可のコピーを作成して返します。
パブリック メソッド Demand  コール スタック内の上位にあるすべての呼び出し元に、現在のインスタンスによって指定されているアクセス許可が与えられていない場合は、実行時に SecurityException を強制します。 (CodeAccessPermission から継承されます。)
パブリック メソッド Deny  コール スタックの上位の呼び出し元が、このメソッドを呼び出すコードを使用して、現在のインスタンスによって指定されるリソースにアクセスできないようにします。 (CodeAccessPermission から継承されます。)
パブリック メソッド Equals  オーバーロードされます。 ( CodeAccessPermission から継承されます。)
パブリック メソッド FromXml オーバーライドされます。 XML エンコーディングから、指定した状態のアクセス許可を再構築します。
パブリック メソッド GetHashCode  ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適した CodeAccessPermission オブジェクトのハッシュ コードを取得します。 (CodeAccessPermission から継承されます。)
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 (Object から継承されます。)
パブリック メソッド Intersect オーバーライドされます。 現在のアクセス許可と指定したアクセス許可の積集合を表すアクセス許可を作成して返します。
パブリック メソッド IsSubsetOf オーバーライドされます。 現在のアクセス許可が、指定したアクセス許可のサブセットかどうかを判断します。
パブリック メソッド PermitOnly  コール スタックの上位の呼び出し元が、このメソッドを呼び出すコードを使用して、現在のインスタンスによって指定されるリソース以外のすべてのリソースにアクセスできないようにします。 (CodeAccessPermission から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。)
パブリック メソッド RevertAll  現在のフレームに対する以前のオーバーライドをすべて削除し、無効にします。 (CodeAccessPermission から継承されます。)
パブリック メソッド RevertAssert  現在のフレームに対する以前の Assert をすべて削除し、無効にします。 (CodeAccessPermission から継承されます。)
パブリック メソッド RevertDeny  現在のフレームに対する以前の Deny をすべて削除し、無効にします。 (CodeAccessPermission から継承されます。)
パブリック メソッド RevertPermitOnly  現在のフレームに対する以前の PermitOnly をすべて削除し、無効にします。 (CodeAccessPermission から継承されます。)
パブリック メソッド ToString  現在のアクセス許可オブジェクトの文字列形式を作成して返します。 (CodeAccessPermission から継承されます。)
パブリック メソッド ToXml オーバーライドされます。 アクセス許可とその現在の状態を表す XML エンコーディングを作成します。
パブリック メソッド Union オーバーライドされます。 現在のアクセス許可と指定したアクセス許可の和集合を表すアクセス許可を作成します。
参照参照

関連項目

StrongNameIdentityPermission クラス
System.Security.Permissions 名前空間
StrongNameIdentityPermission クラス
StrongNamePublicKeyBlob
StrongName
StrongNameMembershipCondition

その他の技術情報

アクセス許可
アクセス許可の要求
厳密な名前付きアセンブリ



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「StrongNameIdentityPermission」の関連用語

StrongNameIdentityPermissionのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



StrongNameIdentityPermissionのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS