ApplicationTrust Class

Namespace: System.Security.Policy

Assembly: System.dll (in System.dll)

Summary

Represents trust that can be granted to an application. This class cannot be inherited.

Remarks

An ApplicationTrust object represents the trust that the computer's policy provider has decided to grant to an application. This trust is expressed in terms of authorization and specific permissions. The ApplicationSecurityManager class is used to manage application trust.

When you create an ApplicationTrust object, you can specify information about the application's publisher, the application's identity, and the permissions the application has been granted. This information is stored as Evidence objects.

The ApplicationTrust class is used in scenarios where an application needs to be granted trust beyond the default security policies configured on a machine. For example, it can be used to grant specific permissions to applications that are downloaded from the internet or run from a network share.

Public Constructors

Constructor Description
ApplicationTrust() Initializes a new instance of the ApplicationTrust class.
ApplicationTrust(string publicKey) Initializes a new instance of the ApplicationTrust class with the specified public key.

Public Properties

Property Description
AppId Gets or sets the unique identifier for the application.
AuthorizationRules Gets the collection of authorization rules for the application.
Description Gets or sets a description of the application.
ExtraData Gets or sets extra data associated with the application trust.
IdentityDefinition Gets or sets the identity definition for the application.
IsRevoked Gets a value indicating whether the application trust is revoked.
Persisted Gets or sets a value indicating whether the application trust is persisted.
TrustValidityUrl Gets or sets the URL that provides trust information for the application.

Public Methods

Method Description
AddAuthorizationRule(IPermission permission) Adds an authorization rule to the application trust.
CreateFromFile(string filename) Creates an ApplicationTrust object from the specified assembly file.
CreateFromFile(string filename, string version) Creates an ApplicationTrust object from the specified assembly file and version.
GetHashCode() Returns the hash code for the current instance.
GetType() Gets the type of the current instance.
ToString() Returns a string representation of the object.

Example

The following code example shows how to create an ApplicationTrust object and add it to the application trust list using the ApplicationSecurityManager.


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

public class ApplicationTrustExample
{
    public static void Main(string[] args)
    {
        // Create a new ApplicationTrust object.
        ApplicationTrust trust = new ApplicationTrust();

        // Specify a publisher's public key (example).
        // In a real scenario, this would be a valid public key.
        trust.IdentityDefinition.PublicKeys.Add(new StrongNamePublicKeyBlob(new byte[] { 0x00, 0x24, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x94, 0x00, 0x00, 0x00, 0x06, 0x02, 0x00, 0x00 }));

        // Grant specific permissions.
        trust.AddAuthorizationRule(new SecurityPermission(SecurityPermissionFlag.Execution));
        trust.AddAuthorizationRule(new FileIOPermission(PermissionState.Unrestricted));

        // Set a description for the application trust.
        trust.Description = "Example application trust for demonstration purposes.";

        // Add the trust to the application trust list.
        try
        {
            ApplicationSecurityManager.AddApplicationTrust(trust);
            Console.WriteLine("Application trust added successfully.");
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Error adding application trust: {ex.Message}");
        }
    }
}
                

See Also