Represents the evidence that can be used to verify the identity of a code principal.
In the .NET Framework, code security is achieved by asserting that specific code has certain permissions. To determine if code has the necessary permissions, the common language runtime (CLR) needs to verify the identity of the code. Evidence is the information used by the CLR to establish the identity of code.
The Evidence class is an unordered collection of objects. Each object in the collection represents a piece of evidence. For example, evidence can include the publisher's certificate, the site from which the code was downloaded, the strong name of the assembly, and the URL of the assembly.
mscorlib.dll
[System.Serializable]
public sealed class Evidence : System.Collections.ICollection, System.Collections.IEnumerable
The Evidence class is used by the .NET security system to determine the trustworthiness of code. When an assembly is loaded, the CLR collects various pieces of information about it, such as its origin, publisher, and strong name. This information is encapsulated in Evidence objects.
Note: The Evidence class is a collection. You can add, remove, and iterate through the evidence objects contained within it.
Initializes a new instance of the Evidence class with no evidence.
Initializes a new instance of the Evidence class with a copy of the specified evidence.
Evidence object.
Adds an object of the specified type to the end of the Evidence collection.
Evidence collection.
Returns: The object that was added to the Evidence collection.
Removes all objects from the Evidence collection.
Creates a copy of the current Evidence object.
Returns: A copy of the current Evidence object.
Copies the entire Evidence collection to a compatible one-dimensional Array, starting at the specified index of the target array.
Array that is the destination of the elements copied from Evidence. The Array must have zero-based indexing. array at which CopyTo begins copying the Evidence collection.
Returns an enumerator that can iterate through the Evidence collection.
Returns: An IEnumerator that can be used to iterate through the Evidence collection.
Removes the first occurrence of the specified Evidence object from the Evidence collection.
Evidence object to remove from the Evidence collection.
Gets the number of elements contained in the Evidence collection.
Gets a value indicating whether access to the Evidence collection is synchronized (thread safe).
Gets an object that can be used for synchronizing access to the Evidence collection.
The following code example demonstrates how to create an Evidence object, add various pieces of evidence to it, and then iterate through the evidence.
using System;
using System.Security.Policy;
using System.Security.Principal;
using System.Collections;
public class EvidenceExample
{
public static void Main(string[] args)
{
// Create a new Evidence object
Evidence evidence = new Evidence();
// Add some common types of evidence
evidence.Add(new Zone(SecurityZone.MyComputer));
evidence.Add(new Url("http://www.contoso.com/mycode.dll"));
evidence.Add(new Hash(new byte[] { 0x12, 0x34, 0x56 }));
Console.WriteLine("Evidence collected:");
// Iterate through the evidence
foreach (object obj in evidence)
{
Console.WriteLine(obj.GetType().Name);
}
// Example of removing evidence
evidence.Remove(new Zone(SecurityZone.MyComputer));
Console.WriteLine("\nAfter removing Zone evidence:");
foreach (object obj in evidence)
{
Console.WriteLine(obj.GetType().Name);
}
}
}
Output:
Evidence collected:
Zone
Url
Hash
After removing Zone evidence:
Url
Hash