# OpcSecurityPolicy Members

> Reference: Describes the configuration used to secure the message exchange.

<dl class="api-definition">
<dt>Type</dt>
<dd><a href="./">OpcSecurityPolicy</a></dd>
<dt>Namespace</dt>
<dd><a href="../namespaces/opc.uafx">Opc.UaFx</a></dd>
<dt>Assembly</dt>
<dd>Opc.UaFx.Advanced.dll</dd>
<dt>Package</dt>
<dd>Opc.UaFx.Advanced v2.59.0</dd>
<dt>Also in</dt>
<dd>Opc.UaFx.Client</dd>
</dl>

## Constructors

### OpcSecurityPolicy

<span class="api-meta">3 overloads</span>

| Overload | Description |
|---|---|
| [OpcSecurityPolicy(OpcSecurityMode)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritypolicy/members#opcsecuritypolicy-opc-uafx-opcsecuritymode) | Initializes a new instance of the [OpcSecurityPolicy](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritypolicy/) class using the `mode` specified to determine the according [Uri](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritypolicy/members#uri) and [Algorithm](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritypolicy/members#algorithm) of the configuration to represent. |
| [OpcSecurityPolicy(OpcSecurityMode, OpcSecurityAlgorithm)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritypolicy/members#opcsecuritypolicy-opc-uafx-opcsecuritymode-opc-uafx-opcsecurityalgorithm) | Initializes a new instance of the [OpcSecurityPolicy](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritypolicy/) class using the `mode` and `algorithm` specified to determine the according [Uri](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritypolicy/members#uri) of the configuration to represent. |
| [OpcSecurityPolicy(OpcSecurityMode, Uri)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritypolicy/members#opcsecuritypolicy-opc-uafx-opcsecuritymode-system-uri) | Initializes a new instance of the [OpcSecurityPolicy](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritypolicy/) class using the `mode` and `uri` specified. |

#### OpcSecurityPolicy(OpcSecurityMode)

Initializes a new instance of the [OpcSecurityPolicy](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritypolicy/) class using the `mode` specified to determine the according [Uri](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritypolicy/members#uri) and [Algorithm](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritypolicy/members#algorithm) of the configuration to represent.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcSecurityPolicy(OpcSecurityMode mode)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Sub New(mode As OpcSecurityMode)
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `mode` | [OpcSecurityMode](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritymode/) | One of the [OpcSecurityMode](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritymode/) members to define the mechanisms to secure the message exchange. |

#### OpcSecurityPolicy(OpcSecurityMode, OpcSecurityAlgorithm)

Initializes a new instance of the [OpcSecurityPolicy](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritypolicy/) class using the `mode` and `algorithm` specified to determine the according [Uri](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritypolicy/members#uri) of the configuration to represent.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcSecurityPolicy(OpcSecurityMode mode, OpcSecurityAlgorithm algorithm)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Sub New(mode As OpcSecurityMode, algorithm As OpcSecurityAlgorithm)
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `mode` | [OpcSecurityMode](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritymode/) | One of the [OpcSecurityMode](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritymode/) members to define the mechanisms to secure the message exchange. |
| `algorithm` | [OpcSecurityAlgorithm](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecurityalgorithm/) | One of the [OpcSecurityAlgorithm](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecurityalgorithm/) members to define the algorithm to use for signing and message encryption (depending on the `mode` specified). Using the algorithm [Auto](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecurityalgorithm/#auto) results into [None](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecurityalgorithm/#none) for the mode [None](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritymode/#none) and into [Basic256Sha256](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecurityalgorithm/#basic256sha256) for the modes [Sign](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritymode/#sign) and [SignAndEncrypt](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritymode/#signandencrypt). The [Algorithm](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritypolicy/members#algorithm) is set to [None](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecurityalgorithm/#none) in case of the algorithm [Custom](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecurityalgorithm/#custom) is used. |

#### OpcSecurityPolicy(OpcSecurityMode, Uri)

Initializes a new instance of the [OpcSecurityPolicy](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritypolicy/) class using the `mode` and `uri` specified.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcSecurityPolicy(OpcSecurityMode mode, Uri uri)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Sub New(mode As OpcSecurityMode, uri As Uri)
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `mode` | [OpcSecurityMode](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritymode/) | One of the [OpcSecurityMode](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritymode/) members to define the mechanisms to secure the message exchange. |
| `uri` | [Uri](https://learn.microsoft.com/dotnet/api/system.uri) | The absolute URI of the security policy configuration to use which identifies the [Algorithm](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritypolicy/members#algorithm) to use for signing and message encryption (depending on the `mode` specified). |

**Exceptions**

| Exception | Condition |
|---|---|
| [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception) | The `uri` is a null reference (Nothing in Visual Basic). |

## Fields

### BaseUri

<span class="api-meta">static</span>

Provides the base URI used by all security policies to refer to the according [OpcSecurityAlgorithm](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecurityalgorithm/) they use.

<div class="api-signature" data-lang="csharp">

```csharp
public static readonly Uri BaseUri
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Shared ReadOnly BaseUri As Uri
```

</div>

**Field value**

[Uri](https://learn.microsoft.com/dotnet/api/system.uri)

## Properties

### Algorithm

Gets the [OpcSecurityAlgorithm](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecurityalgorithm/) used to encrypt messages using the current [OpcSecurityPolicy](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritypolicy/) configuration.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcSecurityAlgorithm Algorithm { get; }
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public ReadOnly Property Algorithm As OpcSecurityAlgorithm
```

</div>

**Property value**

[OpcSecurityAlgorithm](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecurityalgorithm/)

One of the members defined by the [OpcSecurityAlgorithm](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecurityalgorithm/) enumeration or [Custom](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecurityalgorithm/#custom) in case there [Uri](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritypolicy/members#uri) does not refer to a known algorithm.

### Level

Gets an ordinal value to order and classify the current [OpcSecurityPolicy](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritypolicy/) accordingly to others and their security configuration.

<div class="api-signature" data-lang="csharp">

```csharp
public int Level { get; }
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public ReadOnly Property Level As Integer
```

</div>

**Property value**

[Int32](https://learn.microsoft.com/dotnet/api/system.int32)

A positive [int](https://learn.microsoft.com/dotnet/api/system.int32) to identify the most secure policy. The policy with the highest [Level](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritypolicy/members#level) is also the most secure.

### Mode

Gets the mechanism used to secure the message exchange using the current [OpcSecurityPolicy](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritypolicy/) configuration.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcSecurityMode Mode { get; }
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public ReadOnly Property Mode As OpcSecurityMode
```

</div>

**Property value**

[OpcSecurityMode](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritymode/)

One of the members defined by the [OpcSecurityMode](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritymode/) enumeration. The value [Invalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritymode/#invalid) in case of an invalid [OpcSecurityPolicy](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritypolicy/) configuration.

### Uri

Gets the URI which expresses the [Algorithm](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritypolicy/members#algorithm) used for message encryption using the current [OpcSecurityPolicy](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritypolicy/) configuration.

<div class="api-signature" data-lang="csharp">

```csharp
public Uri Uri { get; }
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public ReadOnly Property Uri As Uri
```

</div>

**Property value**

[Uri](https://learn.microsoft.com/dotnet/api/system.uri)

An instance of the [Uri](https://learn.microsoft.com/dotnet/api/system.uri) class which identifies the [Algorithm](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcsecuritypolicy/members#algorithm) used for message encryption.
