# OpcCertificateManager Members

> Reference: Provides a set of static (Shared in Visual Basic) methods to manage certificates.

<dl class="api-definition">
<dt>Type</dt>
<dd><a href="./">OpcCertificateManager</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>

## Methods

### CreateCertificate

<span class="api-meta">static · 4 overloads</span>

| Overload | Description |
|---|---|
| [CreateCertificate(IOpcApplicationInstance)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opccertificatemanager/members#createcertificate-opc-uafx-iopcapplicationinstance)<span class="api-meta">static</span> | Creates a new application instance certificate (in memory) using the application `instance` specified. |
| [CreateCertificate(IOpcApplicationInstance, OpcCertificateStoreInfo)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opccertificatemanager/members#createcertificate-opc-uafx-iopcapplicationinstance-opc-uafx-opccertificatestoreinfo)<span class="api-meta">static</span> | Creates a new application instance certificate using the `instance` specified, while the created certificate will be stored in the certificate store defined by `store`. |
| [CreateCertificate(OpcCertificateSettings)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opccertificatemanager/members#createcertificate-opc-uafx-opccertificatesettings)<span class="api-meta">static</span> | Creates a new application instance certificate (in memory) using the certificate `settings` specified. |
| [CreateCertificate(OpcCertificateSettings, OpcCertificateStoreInfo)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opccertificatemanager/members#createcertificate-opc-uafx-opccertificatesettings-opc-uafx-opccertificatestoreinfo)<span class="api-meta">static</span> | Creates a new application instance certificate using the certificate `settings` specified, while the created certificate will be stored in the certificate store defined by `store`. |

#### CreateCertificate(IOpcApplicationInstance)

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

Creates a new application instance certificate (in memory) using the application `instance` specified.

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

```csharp
public static X509Certificate2 CreateCertificate(
    IOpcApplicationInstance instance)
```

</div>

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

```vbnet
<CLSCompliant(False)>
Public Shared Function CreateCertificate(
    instance As IOpcApplicationInstance) As X509Certificate2
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `instance` | [IOpcApplicationInstance](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.iopcapplicationinstance/) | An instance implementing the [IOpcApplicationInstance](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.iopcapplicationinstance/) interface from that the necessary certificate information is retrieved to create the certificate. |

**Returns**

[X509Certificate2](https://learn.microsoft.com/dotnet/api/system.security.cryptography.x509certificates.x509certificate2)

A new instance of the [X509Certificate2](https://learn.microsoft.com/dotnet/api/system.security.cryptography.x509certificates.x509certificate2) class representing the newly created certificate using the application instance information provided by `instance`.

**Exceptions**

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

#### CreateCertificate(IOpcApplicationInstance, OpcCertificateStoreInfo)

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

Creates a new application instance certificate using the `instance` specified, while the created certificate will be stored in the certificate store defined by `store`.

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

```csharp
public static X509Certificate2 CreateCertificate(
    IOpcApplicationInstance instance,
    OpcCertificateStoreInfo store)
```

</div>

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

```vbnet
<CLSCompliant(False)>
Public Shared Function CreateCertificate(
    instance As IOpcApplicationInstance,
    store As OpcCertificateStoreInfo) As X509Certificate2
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `instance` | [IOpcApplicationInstance](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.iopcapplicationinstance/) | An instance implementing the [IOpcApplicationInstance](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.iopcapplicationinstance/) interface from that the necessary certificate information is retrieved to create the certificate. |
| `store` | [OpcCertificateStoreInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opccertificatestoreinfo/) | The [OpcCertificateStoreInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opccertificatestoreinfo/) of the certificate store to that the newly created certificate is to be added or a null reference (Nothing in Visual Basic) in case there the certificate is to be created in memory. |

**Returns**

[X509Certificate2](https://learn.microsoft.com/dotnet/api/system.security.cryptography.x509certificates.x509certificate2)

A new instance of the [X509Certificate2](https://learn.microsoft.com/dotnet/api/system.security.cryptography.x509certificates.x509certificate2) class representing the newly created certificate using the application instance information provided by `instance`.

**Exceptions**

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

#### CreateCertificate(OpcCertificateSettings)

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

Creates a new application instance certificate (in memory) using the certificate `settings` specified.

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

```csharp
public static X509Certificate2 CreateCertificate(
    OpcCertificateSettings settings)
```

</div>

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

```vbnet
Public Shared Function CreateCertificate(
    settings As OpcCertificateSettings) As X509Certificate2
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `settings` | [OpcCertificateSettings](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opccertificatesettings/) | The [OpcCertificateSettings](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opccertificatesettings/) to use to create the certificate. |

**Returns**

[X509Certificate2](https://learn.microsoft.com/dotnet/api/system.security.cryptography.x509certificates.x509certificate2)

A new instance of the [X509Certificate2](https://learn.microsoft.com/dotnet/api/system.security.cryptography.x509certificates.x509certificate2) class representing the newly created certificate using certificate settings specified.

**Exceptions**

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

#### CreateCertificate(OpcCertificateSettings, OpcCertificateStoreInfo)

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

Creates a new application instance certificate using the certificate `settings` specified, while the created certificate will be stored in the certificate store defined by `store`.

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

```csharp
public static X509Certificate2 CreateCertificate(
    OpcCertificateSettings settings,
    OpcCertificateStoreInfo store)
```

</div>

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

```vbnet
Public Shared Function CreateCertificate(
    settings As OpcCertificateSettings,
    store As OpcCertificateStoreInfo) As X509Certificate2
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `settings` | [OpcCertificateSettings](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opccertificatesettings/) | The [OpcCertificateSettings](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opccertificatesettings/) to use to create the certificate. |
| `store` | [OpcCertificateStoreInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opccertificatestoreinfo/) | The [OpcCertificateStoreInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opccertificatestoreinfo/) of the certificate store to that the newly created certificate is to be added or a null reference (Nothing in Visual Basic) in case there the certificate is to be created in memory. |

**Returns**

[X509Certificate2](https://learn.microsoft.com/dotnet/api/system.security.cryptography.x509certificates.x509certificate2)

A new instance of the [X509Certificate2](https://learn.microsoft.com/dotnet/api/system.security.cryptography.x509certificates.x509certificate2) class representing the newly created certificate using certificate settings specified.

**Exceptions**

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

### LoadCertificate

<span class="api-meta">static · 2 overloads</span>

| Overload | Description |
|---|---|
| [LoadCertificate(string)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opccertificatemanager/members#loadcertificate-system-string)<span class="api-meta">static</span> | Loads the application instance certificate using the certificate file specified by `filePath`. |
| [LoadCertificate(string, string)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opccertificatemanager/members#loadcertificate-system-string-system-string)<span class="api-meta">static</span> | Loads the application instance certificate using the certificate file specified by `filePath`. |

**Exceptions (all overloads)**

| Exception | Condition |
|---|---|
| [ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception) | The `filePath` is an empty string. |
| [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception) | The `filePath` is a null reference (Nothing in Visual Basic). |
| [FileNotFoundException](https://learn.microsoft.com/dotnet/api/system.io.filenotfoundexception) | The certificate file specified by `filePath` could not found. |

#### LoadCertificate(string)

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

Loads the application instance certificate using the certificate file specified by `filePath`.

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

```csharp
public static X509Certificate2 LoadCertificate(string filePath)
```

</div>

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

```vbnet
Public Shared Function LoadCertificate(filePath As String) As X509Certificate2
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `filePath` | [String](https://learn.microsoft.com/dotnet/api/system.string) | The file path of the certificate file to load. |

**Returns**

[X509Certificate2](https://learn.microsoft.com/dotnet/api/system.security.cryptography.x509certificates.x509certificate2)

A new instance of the [X509Certificate2](https://learn.microsoft.com/dotnet/api/system.security.cryptography.x509certificates.x509certificate2) class representing the certificate specified by `filePath`.

#### LoadCertificate(string, string)

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

Loads the application instance certificate using the certificate file specified by `filePath`.

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

```csharp
public static X509Certificate2 LoadCertificate(string filePath, string password)
```

</div>

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

```vbnet
Public Shared Function LoadCertificate(
    filePath As String,
    password As String) As X509Certificate2
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `filePath` | [String](https://learn.microsoft.com/dotnet/api/system.string) | The file path of the certificate file load. |
| `password` | [String](https://learn.microsoft.com/dotnet/api/system.string) | The optional password required to access the certificate or a null reference (Nothing in Visual Basic), if there is no password required by the certificate file. |

**Returns**

[X509Certificate2](https://learn.microsoft.com/dotnet/api/system.security.cryptography.x509certificates.x509certificate2)

A new instance of the [X509Certificate2](https://learn.microsoft.com/dotnet/api/system.security.cryptography.x509certificates.x509certificate2) class representing the certificate specified by `filePath`.

### SaveCertificate

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

Saves the application instance `certificate` to the `filePath` specified.

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

```csharp
public static void SaveCertificate(
    string filePath,
    X509Certificate2 certificate)
```

</div>

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

```vbnet
Public Shared Sub SaveCertificate(
    filePath As String,
    certificate As X509Certificate2)
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `filePath` | [String](https://learn.microsoft.com/dotnet/api/system.string) | The full qualified path to the certificate file to write. |
| `certificate` | [X509Certificate2](https://learn.microsoft.com/dotnet/api/system.security.cryptography.x509certificates.x509certificate2) | The [X509Certificate2](https://learn.microsoft.com/dotnet/api/system.security.cryptography.x509certificates.x509certificate2) instance its certificate information is to be written to the `filePath`. |

**Exceptions**

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

## Events

### QueryInstance

<span class="api-meta">static · since v2.7</span>

Occurs when a [X509Certificate2](https://learn.microsoft.com/dotnet/api/system.security.cryptography.x509certificates.x509certificate2) instance is to be created using several certificate and key information. This event can be used to create new [X509Certificate2](https://learn.microsoft.com/dotnet/api/system.security.cryptography.x509certificates.x509certificate2) instances while considering custom, platform and operating system related restrictions.

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

```csharp
public static event OpcCertificateQueryInstanceEventHandler QueryInstance
```

</div>

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

```vbnet
Public Shared Event QueryInstance As OpcCertificateQueryInstanceEventHandler
```

</div>

**Event type**

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