Evidence 클래스
보안 정책 결정의 입력을 구성하는 정보 집합을 정의합니다. 이 클래스는 상속될 수 없습니다.
네임스페이스: System.Security.Policy
어셈블리: mscorlib(mscorlib.dll)
구문
‘선언
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class Evidence
Implements ICollection, IEnumerable
‘사용 방법
Dim instance As Evidence
[SerializableAttribute]
[ComVisibleAttribute(true)]
public sealed class Evidence : ICollection, IEnumerable
[SerializableAttribute]
[ComVisibleAttribute(true)]
public ref class Evidence sealed : ICollection, IEnumerable
/** @attribute SerializableAttribute() */
/** @attribute ComVisibleAttribute(true) */
public final class Evidence implements ICollection, IEnumerable
SerializableAttribute
ComVisibleAttribute(true)
public final class Evidence implements ICollection, IEnumerable
설명
증명 정보의 일반적인 형식에는 서명 및 코드 원본의 위치가 포함되지만 사실 어떠한 항목도 될 수 있습니다. 보안 정책에서 인식하는 모든 형식의 개체는 증명 정보를 나타냅니다.
보안 정책은 코드 그룹으로 구성되고 특정 어셈블리(보안 권한 부여의 기본 코드 단위)는 코드 그룹의 멤버 자격 조건을 만족한다면 해당 코드 그룹의 멤버입니다. 증명 정보는 멤버 자격 조건에서 어셈블리가 속한 코드 그룹을 결정하는 데 사용하는 정책에 대한 입력 집합입니다.
Evidence 클래스는 증명 정보를 나타내는 개체 집합을 유지하는 컬렉션입니다. ICollection을 참조하십시오. 이 클래스는 증명 정보 소스에 해당하는 두 개의 집합, 즉 호스트 증명 정보 및 어셈블리 증명 정보를 유지합니다.
코드의 권한을 평가할 때 정책에서는 두 개의 서로 다른 소스에서 증명 정보를 가져올 수 있습니다.
Host evidence는 호스트에서 제공하며 ControlEvidence 권한이 부여된 호스트만 제공할 수 있습니다. 이것은 일반적으로 코드의 원본 증명 정보이며 어셈블리에 대한 디지털 서명입니다. 일반적으로 원본에 대한 증명 정보에는 Url, Site 및 Zone 증명 정보가 포함됩니다. 서명은 소프트웨어 게시자(AuthentiCode X.509v3 서명) 및 강력한 이름 ID를 참조합니다. 디지털 서명에 기반한 두 종류의 ID는 모두 어셈블리에 빌드되지만 로드될 때 보안 시스템에서 서명을 확인하여 호스트에서 확인하고 정책으로 전달해야 합니다. 그런 다음 해당 서명이 올바른 경우에만 적절한 증명 정보를 만들어 정책으로 전달합니다.
Assembly evidence는 어셈블리의 일부입니다. 개발자나 관리자는 어셈블리에 사용자 지정 증명 정보를 첨부하여 정책에 대한 증명 정보 집합을 확장할 수 있습니다. 어셈블리에 서명하기 전 어셈블리를 생성하는 시점에만 어셈블리 증명 정보를 추가할 수 있습니다. 어셈블리에서 제공한 증명 정보를 무시하는 것이 보안 시스템의 기본 정책이지만 이를 허용하도록 정책을 확장할 수 있습니다.
예제
다음 코드 예제에서는 호스트 증명 정보 및 어셈블리 증명 정보를 모두 사용하여 새 Evidence 클래스를 만드는 방법을 보여 줍니다.
Imports System
Imports System.Collections
Imports System.Security
Imports System.Security.Policy
Imports System.Security.Permissions
Imports System.Globalization
Imports Microsoft.VisualBasic
Public Class Evidence_Example
Public Function CreateEvidence() As Boolean
Dim retVal As Boolean = True
Try
' Create empty evidence using the default contructor.
Dim ev1 As New Evidence
Console.WriteLine("Created empty evidence with the default constructor.")
' Constructor used to create null host evidence.
Dim ev2a As New Evidence(Nothing)
Console.WriteLine("Created an Evidence object with null host evidence.")
' Constructor used to create host evidence.
Dim url As New Url("http://www.treyresearch.com")
Console.WriteLine(("Adding host evidence " & url.ToString()))
ev2a.AddHost(url)
Dim ev2b As New Evidence(ev2a)
Console.WriteLine("Copy evidence into new evidence")
Dim enum1 As IEnumerator = ev2b.GetHostEnumerator()
enum1.MoveNext()
Console.WriteLine(enum1.Current.ToString())
' Constructor used to create both host and assembly evidence.
Dim oa1() As [Object]
Dim site As New Site("www.wideworldimporters.com")
Dim oa2 As [Object]() = {url, site}
Dim ev3a As New Evidence(oa1, oa2)
enum1 = ev3a.GetHostEnumerator()
Dim enum2 As IEnumerator = ev3a.GetAssemblyEnumerator()
enum2.MoveNext()
Dim obj1 As [Object] = enum2.Current
enum2.MoveNext()
Console.WriteLine(("URL = " & obj1.ToString() & " Site = " & enum2.Current.ToString()))
' Constructor used to create null host and null assembly evidence.
Dim ev3b As New Evidence(Nothing, Nothing)
Console.WriteLine("Create new evidence with null host and assembly evidence")
Catch e As Exception
Console.WriteLine("Fatal error: {0}", e.ToString())
Return False
End Try
Return retVal
End Function 'CreateEvidence
Public Function DemonstrateEvidenceMembers() As Evidence
Dim myEvidence As New Evidence
Dim sPubKeyBlob As String = "00240000048000009400000006020000" & "00240000525341310004000001000100" & "19390E945A40FB5730204A25FA5DC4DA" & "B18688B412CB0EDB87A6EFC50E2796C9" & "B41AD3040A7E46E4A02516C598678636" & "44A0F74C39B7AB9C38C01F10AF4A5752" & "BFBCDF7E6DD826676AD031E7BCE63393" & "495BAD2CA4BE03B529A73C95E5B06BE7" & "35CA0F622C63E8F54171BD73E4C8F193" & "CB2664163719CA41F8159B8AC88F8CD3"
Dim pubkey As [Byte]() = HexsToArray(sPubKeyBlob)
' Create a strong name.
Dim mSN As New StrongName(New StrongNamePublicKeyBlob(pubkey), "SN01", New Version("0.0.0.0"))
' Create assembly and host evidence.
Console.WriteLine("Adding assembly evidence.")
myEvidence.AddAssembly("SN01")
myEvidence.AddAssembly(New Version("0.0.0.0"))
myEvidence.AddAssembly(mSN)
Console.WriteLine(("Count of evidence items = " & myEvidence.Count.ToString()))
Dim url As New Url("http://www.treyresearch.com")
Console.WriteLine(("Adding host evidence " & url.ToString()))
myEvidence.AddHost(url)
PrintEvidence(myEvidence).ToString()
Console.WriteLine(("Count of evidence items = " & myEvidence.Count.ToString()))
Console.WriteLine(ControlChars.Lf & "Copy the evidence to an array using CopyTo, then display the array.")
Dim evidenceArray(myEvidence.Count - 1) As Object
myEvidence.CopyTo(evidenceArray, 0)
Dim obj As Object
For Each obj In evidenceArray
Console.WriteLine(obj.ToString())
Next obj
Console.WriteLine(ControlChars.Lf & "Display the contents of the properties.")
Console.WriteLine("Locked is the only property normally used by code.")
Console.WriteLine("IsReadOnly, IsSynchronized, and SyncRoot properties are not normally used.")
Console.WriteLine((ControlChars.Lf & "The default value for the Locked property = " & myEvidence.Locked.ToString()))
Console.WriteLine(ControlChars.Lf & "Get the hashcode for the evidence.")
Console.WriteLine(("HashCode = " & myEvidence.GetHashCode().ToString()))
Console.WriteLine(ControlChars.Lf & "Get the type for the evidence.")
Console.WriteLine(("Type = " & myEvidence.GetType().ToString()))
Console.WriteLine(ControlChars.Lf & "Merge new evidence with the current evidence.")
Dim oa1() As [Object]
Dim site As New Site("www.wideworldimporters.com")
Dim oa2 As [Object]() = {url, site}
Dim newEvidence As New Evidence(oa1, oa2)
myEvidence.Merge(newEvidence)
Console.WriteLine(("Evidence count = " & PrintEvidence(myEvidence).ToString()))
Console.WriteLine(ControlChars.Lf & "Remove URL evidence.")
myEvidence.RemoveType(url.GetType())
Console.WriteLine(("Evidence count is now: " & myEvidence.Count.ToString()))
Console.WriteLine(ControlChars.Lf & "Make a copy of the current evidence.")
Dim evidenceCopy As New Evidence(myEvidence)
Console.WriteLine(("Count of new evidence items = " & evidenceCopy.Count.ToString()))
Console.WriteLine(("Does the copy equal the current evidence? " & myEvidence.Equals(evidenceCopy)))
Console.WriteLine(ControlChars.Lf & "Clear the current evidence.")
myEvidence.Clear()
Console.WriteLine(("Count is now " & myEvidence.Count.ToString()))
Return myEvidence
End Function 'DemonstrateEvidenceMembers
Public Shared Function PrintEvidence(ByVal myEvidence As Evidence) As Integer
Dim p As Integer = 0
Console.WriteLine(ControlChars.Lf & "Current evidence = ")
If myEvidence Is Nothing Then
Return 0
End If
Dim list As IEnumerator = myEvidence.GetEnumerator()
Dim obj As Object
While list.MoveNext()
Console.WriteLine(list.Current.ToString())
p = p + 1
End While
Console.WriteLine(ControlChars.Lf)
Return p
End Function 'PrintEvidence
' Convert a hexidecimal string to an array.
Public Shared Function HexsToArray(ByVal sHexString As String) As Byte()
Dim array(sHexString.Length / 2) As [Byte]
Dim i As Integer
For i = 0 To sHexString.Length - 2 Step 2
array((i / 2)) = [Byte].Parse(sHexString.Substring(i, 2), NumberStyles.HexNumber)
Next i
Return array
End Function 'HexsToArray
' Main method.
Public Shared Sub Main()
Try
Dim EvidenceTest As New Evidence_Example
Dim ret As Boolean = EvidenceTest.CreateEvidence()
If ret Then
Console.WriteLine("Evidence successfully created.")
Else
Console.WriteLine("Evidence creation failed.")
End If
EvidenceTest.DemonstrateEvidenceMembers()
Catch e As Exception
Console.WriteLine(e.ToString())
Environment.ExitCode = 101
End Try
End Sub 'Main
End Class 'Evidence_Example
using System;
using System.Collections;
using System.Security;
using System.Security.Policy;
using System.Security.Permissions;
using System.Globalization;
public class Evidence_Example
{
public bool CreateEvidence()
{
bool retVal = true;
try
{
// Create empty evidence using the default contructor.
Evidence ev1 = new Evidence();
Console.WriteLine("Created empty evidence with the default constructor.");
// Constructor used to create null host evidence.
Evidence ev2a = new Evidence(null);
Console.WriteLine("Created an Evidence object with null host evidence.");
// Constructor used to create host evidence.
Url url = new Url("http://www.treyresearch.com");
Console.WriteLine("Adding host evidence " + url.ToString());
ev2a.AddHost(url);
Evidence ev2b = new Evidence(ev2a);
Console.WriteLine("Copy evidence into new evidence");
IEnumerator enum1 = ev2b.GetHostEnumerator();
enum1.MoveNext();
Console.WriteLine(enum1.Current.ToString());
// Constructor used to create both host and assembly evidence.
Object [] oa1 = {};
Site site = new Site("www.wideworldimporters.com");
Object [] oa2 = { url, site };
Evidence ev3a = new Evidence(oa1, oa2);
enum1 = ev3a.GetHostEnumerator();
IEnumerator enum2 = ev3a.GetAssemblyEnumerator();
enum2.MoveNext();
Object obj1 = enum2.Current;
enum2.MoveNext();
Console.WriteLine("URL = " + obj1.ToString() + " Site = " + enum2.Current.ToString());
// Constructor used to create null host and null assembly evidence.
Evidence ev3b = new Evidence(null, null);
Console.WriteLine("Create new evidence with null host and assembly evidence");
}
catch (Exception e)
{
Console.WriteLine("Fatal error: {0}", e.ToString());
return false;
}
return retVal;
}
public Evidence DemonstrateEvidenceMembers()
{
Evidence myEvidence = new Evidence();
string sPubKeyBlob = "00240000048000009400000006020000" +
"00240000525341310004000001000100" +
"19390E945A40FB5730204A25FA5DC4DA" +
"B18688B412CB0EDB87A6EFC50E2796C9" +
"B41AD3040A7E46E4A02516C598678636" +
"44A0F74C39B7AB9C38C01F10AF4A5752" +
"BFBCDF7E6DD826676AD031E7BCE63393" +
"495BAD2CA4BE03B529A73C95E5B06BE7" +
"35CA0F622C63E8F54171BD73E4C8F193" +
"CB2664163719CA41F8159B8AC88F8CD3";
Byte[] pubkey = HexsToArray(sPubKeyBlob);
// Create a strong name.
StrongName mSN = new StrongName(new StrongNamePublicKeyBlob(pubkey), "SN01", new Version("0.0.0.0"));
// Create assembly and host evidence.
Console.WriteLine("Adding assembly evidence.");
myEvidence.AddAssembly("SN01");
myEvidence.AddAssembly(new Version("0.0.0.0"));
myEvidence.AddAssembly(mSN);
Console.WriteLine("Count of evidence items = " + myEvidence.Count.ToString());
Url url = new Url("http://www.treyresearch.com");
Console.WriteLine("Adding host evidence " + url.ToString());
myEvidence.AddHost(url);
PrintEvidence(myEvidence).ToString();
Console.WriteLine("Count of evidence items = " + myEvidence.Count.ToString());
Console.WriteLine("\nCopy the evidence to an array using CopyTo, then display the array.");
object[] evidenceArray = new object[myEvidence.Count];
myEvidence.CopyTo(evidenceArray, 0);
foreach (object obj in evidenceArray)
{
Console.WriteLine(obj.ToString());
}
Console.WriteLine("\nDisplay the contents of the properties.");
Console.WriteLine("Locked is the only property normally used by code.");
Console.WriteLine("IsReadOnly, IsSynchronized, and SyncRoot properties are not normally used.");
Console.WriteLine("\nThe default value for the Locked property = " + myEvidence.Locked.ToString());
Console.WriteLine("\nGet the hashcode for the evidence.");
Console.WriteLine("HashCode = " + myEvidence.GetHashCode().ToString());
Console.WriteLine("\nGet the type for the evidence.");
Console.WriteLine("Type = " + myEvidence.GetType().ToString());
Console.WriteLine("\nMerge new evidence with the current evidence.");
Object [] oa1 = {};
Site site = new Site("www.wideworldimporters.com");
Object [] oa2 = { url, site };
Evidence newEvidence = new Evidence(oa1, oa2);
myEvidence.Merge(newEvidence);
Console.WriteLine("Evidence count = " + PrintEvidence(myEvidence).ToString());
Console.WriteLine("\nRemove URL evidence.");
myEvidence.RemoveType(url.GetType());
Console.WriteLine("Evidence count is now: " + myEvidence.Count.ToString());
Console.WriteLine("\nMake a copy of the current evidence.");
Evidence evidenceCopy = new Evidence(myEvidence);
Console.WriteLine("Count of new evidence items = " + evidenceCopy.Count);
Console.WriteLine("Does the copy equal the current evidence? " + myEvidence.Equals(evidenceCopy));
Console.WriteLine("\nClear the current evidence.");
myEvidence.Clear();
Console.WriteLine("Count is now " + myEvidence.Count.ToString());
return myEvidence;
}
public static int PrintEvidence(Evidence myEvidence)
{
int p = 0;
Console.WriteLine("\nCurrent evidence = ");
if (null == myEvidence) return 0;
IEnumerator list = myEvidence.GetEnumerator();
while (list.MoveNext())
{
Console.WriteLine(list.Current.ToString());
}
Console.WriteLine("\n");
return p;
}
// Convert a hexidecimal string to an array.
public static byte[] HexsToArray(string sHexString)
{
Byte[] array = new Byte[sHexString.Length/2];
for (int i = 0; i < sHexString.Length; i += 2)
{
array[i / 2] = Byte.Parse(sHexString.Substring(i, 2), NumberStyles.HexNumber);
}
return array;
}
// Main method.
public static void Main()
{
try
{
Evidence_Example EvidenceTest = new Evidence_Example();
bool ret = EvidenceTest.CreateEvidence();
if (ret)
{
Console.WriteLine("Evidence successfully created.");
}
else
{
Console.WriteLine("Evidence creation failed.");
}
EvidenceTest.DemonstrateEvidenceMembers();
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
Environment.ExitCode = 101;
}
}
}
using namespace System;
using namespace System::Collections;
using namespace System::Security;
using namespace System::Security::Policy;
using namespace System::Security::Permissions;
using namespace System::Globalization;
public ref class Evidence_Example
{
public:
bool CreateEvidence()
{
bool retVal = true;
try
{
// Create empty evidence using the default contructor.
Evidence^ ev1 = gcnew Evidence;
Console::WriteLine( "Created empty evidence with the default constructor." );
// Constructor used to create null host evidence.
Evidence^ ev2a = gcnew Evidence( nullptr );
Console::WriteLine( "Created an Evidence object with null host evidence." );
// Constructor used to create host evidence.
Url^ url = gcnew Url( "http://www.treyresearch.com" );
Console::WriteLine( "Adding host evidence {0}", url );
ev2a->AddHost( url );
Evidence^ ev2b = gcnew Evidence( ev2a );
Console::WriteLine( "Copy evidence into new evidence" );
IEnumerator^ enum1 = ev2b->GetHostEnumerator();
enum1->MoveNext();
Console::WriteLine( enum1->Current );
// Constructor used to create both host and assembly evidence.
array<Object^>^oa1 = {};
Site^ site = gcnew Site( "www.wideworldimporters.com" );
array<Object^>^oa2 = {url,site};
Evidence^ ev3a = gcnew Evidence( oa1,oa2 );
enum1 = ev3a->GetHostEnumerator();
IEnumerator^ enum2 = ev3a->GetAssemblyEnumerator();
enum2->MoveNext();
Object^ obj1 = enum2->Current;
enum2->MoveNext();
Console::WriteLine( "URL = {0} Site = {1}", obj1, enum2->Current );
// Constructor used to create null host and null assembly evidence.
Evidence^ ev3b = gcnew Evidence( nullptr,nullptr );
Console::WriteLine( "Create new evidence with null host and assembly evidence" );
}
catch ( Exception^ e )
{
Console::WriteLine( "Fatal error: {0}", e );
return false;
}
return retVal;
}
Evidence^ DemonstrateEvidenceMembers()
{
Evidence^ myEvidence = gcnew Evidence;
String^ sPubKeyBlob = "00240000048000009400000006020000"
"00240000525341310004000001000100"
"19390E945A40FB5730204A25FA5DC4DA"
"B18688B412CB0EDB87A6EFC50E2796C9"
"B41AD3040A7E46E4A02516C598678636"
"44A0F74C39B7AB9C38C01F10AF4A5752"
"BFBCDF7E6DD826676AD031E7BCE63393"
"495BAD2CA4BE03B529A73C95E5B06BE7"
"35CA0F622C63E8F54171BD73E4C8F193"
"CB2664163719CA41F8159B8AC88F8CD3";
array<Byte>^pubkey = HexsToArray( sPubKeyBlob );
// Create a strong name.
StrongName^ mSN = gcnew StrongName( gcnew StrongNamePublicKeyBlob( pubkey ),"SN01",gcnew Version( "0.0.0.0" ) );
// Create assembly and host evidence.
Console::WriteLine( "Adding assembly evidence." );
myEvidence->AddAssembly( "SN01" );
myEvidence->AddAssembly( gcnew Version( "0.0.0.0" ) );
myEvidence->AddAssembly( mSN );
Console::WriteLine( "Count of evidence items = {0}", myEvidence->Count );
Url^ url = gcnew Url( "http://www.treyresearch.com" );
Console::WriteLine( "Adding host evidence {0}", url );
myEvidence->AddHost( url );
PrintEvidence( myEvidence ).ToString();
Console::WriteLine( "Count of evidence items = {0}", myEvidence->Count );
Console::WriteLine( "\nCopy the evidence to an array using CopyTo, then display the array." );
array<Object^>^evidenceArray = gcnew array<Object^>(myEvidence->Count);
myEvidence->CopyTo( evidenceArray, 0 );
for each (Object^ obj in evidenceArray)
{
Console::WriteLine(obj->ToString());
}
Console::WriteLine( "\nDisplay the contents of the properties." );
Console::WriteLine( "Locked is the only property normally used by code." );
Console::WriteLine( "IsReadOnly, IsSynchronized, and SyncRoot properties are not normally used." );
Console::WriteLine( "\nThe default value for the Locked property = {0}", myEvidence->Locked );
Console::WriteLine( "\nGet the hashcode for the evidence." );
Console::WriteLine( "HashCode = {0}", myEvidence->GetHashCode() );
Console::WriteLine( "\nGet the type for the evidence." );
Console::WriteLine( "Type = {0}", myEvidence->GetType() );
Console::WriteLine( "\nMerge new evidence with the current evidence." );
array<Object^>^oa1 = {};
Site^ site = gcnew Site( "www.wideworldimporters.com" );
array<Object^>^oa2 = {url,site};
Evidence^ newEvidence = gcnew Evidence( oa1,oa2 );
myEvidence->Merge( newEvidence );
Console::WriteLine( "Evidence count = {0}", PrintEvidence( myEvidence ) );
Console::WriteLine( "\nRemove URL evidence." );
myEvidence->RemoveType( url->GetType() );
Console::WriteLine( "Evidence count is now: {0}", myEvidence->Count );
Console::WriteLine( "\nMake a copy of the current evidence." );
Evidence^ evidenceCopy = gcnew Evidence( myEvidence );
Console::WriteLine( "Count of new evidence items = {0}", evidenceCopy->Count );
Console::WriteLine( "Does the copy equal the current evidence? {0}", myEvidence->Equals( evidenceCopy ) );
Console::WriteLine( "\nClear the current evidence." );
myEvidence->Clear();
Console::WriteLine( "Count is now {0}", myEvidence->Count );
return myEvidence;
}
static int PrintEvidence( Evidence^ myEvidence )
{
int p = 0;
Console::WriteLine( "\nCurrent evidence = " );
if ( nullptr == myEvidence )
return 0;
IEnumerator^ list = myEvidence->GetEnumerator();
IEnumerator^ myEnum1 = list;
while ( myEnum1->MoveNext() )
{
Object^ obj = safe_cast<Object^>(myEnum1->Current);
Console::WriteLine( obj );
p++;
}
Console::WriteLine( "\n" );
return p;
}
// Convert a hexadecimal string to an array.
static array<Byte>^ HexsToArray( String^ sHexString )
{
array<Byte>^arr = gcnew array<Byte>(sHexString->Length / 2);
for ( int i = 0; i < sHexString->Length; i += 2 )
{
arr[ i / 2 ] = Byte::Parse( sHexString->Substring( i, 2 ), NumberStyles::HexNumber );
}
return arr;
}
};
// Main method.
int main()
{
try
{
Evidence_Example^ EvidenceTest = gcnew Evidence_Example;
bool ret = EvidenceTest->CreateEvidence();
if ( ret )
{
Console::WriteLine( "Evidence successfully created." );
}
else
{
Console::WriteLine( "Evidence creation failed." );
}
EvidenceTest->DemonstrateEvidenceMembers();
}
catch ( Exception^ e )
{
Console::WriteLine( e );
Environment::ExitCode = 101;
}
}
import System.*;
import System.Collections.*;
import System.Security.*;
import System.Security.Policy.*;
import System.Security.Permissions.*;
import System.Globalization.*;
import System.Byte;
public class EvidenceExample
{
public boolean CreateEvidence()
{
boolean retVal = true;
try {
// Create empty evidence using the default contructor.
Evidence ev1 = new Evidence();
Console.WriteLine("Created empty evidence with the "
+ " default constructor.");
// Constructor used to create null host evidence.
Evidence ev2a = new Evidence(null);
Console.WriteLine("Created an Evidence object with "
+ " null host evidence.");
// Constructor used to create host evidence.
Url url = new Url("http://www.treyresearch.com");
Console.WriteLine(("Adding host evidence " + url.ToString()));
ev2a.AddHost(url);
Evidence ev2b = new Evidence(ev2a);
Console.WriteLine("Copy evidence into new evidence");
IEnumerator enum1 = ev2b.GetHostEnumerator();
enum1.MoveNext();
Console.WriteLine(enum1.get_Current().ToString());
// Constructor used to create both host and assembly evidence.
Object oa1[] = null;
Site site = new Site("www.wideworldimporters.com");
Object oa2[] = { url, site };
Evidence ev3a = new Evidence(oa1, oa2);
enum1 = ev3a.GetHostEnumerator();
IEnumerator enum2 = ev3a.GetAssemblyEnumerator();
enum2.MoveNext();
Object obj1 = enum2.get_Current();
enum2.MoveNext();
Console.WriteLine(("URL = " + obj1.ToString() + " Site = "
+ enum2.get_Current().ToString()));
// Constructor used to create null host and null assembly evidence.
Evidence ev3b = new Evidence(null, null);
Console.WriteLine("Create new evidence with null host and "
+ " assembly evidence");
}
catch (System.Exception e) {
Console.WriteLine("Fatal error: {0}", e.ToString());
return false;
}
return retVal;
} //CreateEvidence
public Evidence DemonstrateEvidenceMembers()
{
Evidence myEvidence = new Evidence();
String sPubKeyBlob = "00240000525341310004000001000100"
+ "19390E945A40FB5730204A25FA5DC4DA"
+ "B18688B412CB0EDB87A6EFC50E2796C9"
+ "B41AD3040A7E46E4A02516C598678636"
+ "44A0F74C39B7AB9C38C01F10AF4A5752"
+ "BFBCDF7E6DD826676AD031E7BCE63393"
+ "495BAD2CA4BE03B529A73C95E5B06BE7"
+ "35CA0F622C63E8F54171BD73E4C8F193"
+ "CB2664163719CA41F8159B8AC88F8CD3";
Byte pubkey[] = HexsToArray(sPubKeyBlob);
// Create a strong name.
StrongName mSN = new StrongName(
new StrongNamePublicKeyBlob((ubyte[])pubkey), "SN01",
new Version("0.0.0.0"));
// Create assembly and host evidence.
Console.WriteLine("Adding assembly evidence.");
myEvidence.AddAssembly("SN01");
myEvidence.AddAssembly(new Version("0.0.0.0"));
myEvidence.AddAssembly(mSN);
Console.WriteLine(("Count of evidence items = "
+ myEvidence.get_Count()));
Url url = new Url("http://www.treyresearch.com");
Console.WriteLine(("Adding host evidence " + url.ToString()));
myEvidence.AddHost(url);
String.valueOf(PrintEvidence(myEvidence));
Console.WriteLine(("Count of evidence items = "
+ myEvidence.get_Count()));
Console.WriteLine("\nCopy the evidence to an array using CopyTo,"
+ " then display the array.");
Object evidenceArray[] = new Object[myEvidence.get_Count()];
myEvidence.CopyTo(evidenceArray, 0);
for (int objCount = 0; objCount < evidenceArray.length; objCount++) {
Object obj = evidenceArray[objCount];
Console.WriteLine(obj.ToString());
}
Console.WriteLine("\nDisplay the contents of the properties.");
Console.WriteLine("Locked is the only property normally used by code.");
Console.WriteLine("IsReadOnly, IsSynchronized, and SyncRoot "
+ " properties are not normally used.");
Console.WriteLine(("\nThe default value for the Locked property = "
+ System.Convert.ToString(myEvidence.get_Locked())));
Console.WriteLine("\nGet the hashcode for the evidence.");
Console.WriteLine(("HashCode = " + myEvidence.GetHashCode()));
Console.WriteLine("\nGet the type for the evidence.");
Console.WriteLine(("Type = " + myEvidence.GetType().ToString()));
Console.WriteLine("\nMerge new evidence with the current evidence.");
Object oa1[] = null;
Site site = new Site("www.wideworldimporters.com");
Object oa2[] = { url, site };
Evidence newEvidence = new Evidence(oa1, oa2);
myEvidence.Merge(newEvidence);
Console.WriteLine(("Evidence count = " + PrintEvidence(myEvidence)));
Console.WriteLine("\nRemove URL evidence.");
myEvidence.RemoveType(url.GetType());
Console.WriteLine(("Evidence count is now: " + myEvidence.get_Count()));
Console.WriteLine("\nMake a copy of the current evidence.");
Evidence evidenceCopy = new Evidence(myEvidence);
Console.WriteLine(("Count of new evidence items = "
+ evidenceCopy.get_Count()));
Console.WriteLine(("Does the copy equal the current evidence? "
+ System.Convert.ToString(myEvidence.Equals(evidenceCopy))));
Console.WriteLine("\nClear the current evidence.");
myEvidence.Clear();
Console.WriteLine(("Count is now " + myEvidence.get_Count()));
return myEvidence;
} //DemonstrateEvidenceMembers
public static int PrintEvidence(Evidence myEvidence)
{
int p = 0;
Console.WriteLine("\nCurrent evidence = ");
if (null == myEvidence) {
return 0;
}
IEnumerator list = myEvidence.GetEnumerator();
while (list.MoveNext()) {
Console.WriteLine(String.valueOf(list.get_Current()));
}
Console.WriteLine("\n");
return p;
} //PrintEvidence
public static System.Byte[] HexsToArray(String sHexString)
{
Byte array[] = new Byte[sHexString.get_Length() / 2];
for (int i = 0; i < sHexString.get_Length(); i += 2) {
array[i / 2] = (Byte)Byte.Parse(sHexString.Substring(i, 2),
NumberStyles.HexNumber);
}
return array;
} //HexsToArray
public static void main(String[] args)
{
try {
EvidenceExample EvidenceTest = new EvidenceExample();
boolean ret = EvidenceTest.CreateEvidence();
if (ret) {
Console.WriteLine("Evidence successfully created.");
}
else {
Console.WriteLine("Evidence creation failed.");
}
EvidenceTest.DemonstrateEvidenceMembers();
}
catch (System.Exception e) {
Console.WriteLine(e.ToString());
Environment.set_ExitCode(101);
}
} //main
} //EvidenceExample
상속 계층 구조
System.Object
System.Security.Policy.Evidence
스레드로부터의 안전성
이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.
플랫폼
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.
버전 정보
.NET Framework
2.0, 1.1, 1.0에서 지원
.NET Compact Framework
2.0, 1.0에서 지원