System.Security.Principal.Evidence Class

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.

Namespace

System.Security.Principal

Assembly

mscorlib.dll

Syntax

[System.Serializable]
public sealed class Evidence : System.Collections.ICollection, System.Collections.IEnumerable

Remarks

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.

Constructors

Methods

Properties

Example

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

Requirements

Platform:
Works on .NET Framework.

Header:
Declared in mscorlib.dll

Namespace:
Use System.Security.Principal