---
title: "Asn1Util"
description: "Namespace: Lacuna.Pki.Asn1"
canonical: "https://docs.lacunasoftware.com/api/Lacuna.Pki.Asn1/Asn1Util"
locale: "pt-BR"
product: "PKI SDK"
last_updated: "2026-06-02"
---

# Asn1Util

**Namespace:** `Lacuna.Pki.Asn1`  
**Assembly:** `Lacuna.Pki`  
_Class_

```csharp
public static class Asn1Util
```

**Hierarquia:** [`object`](https://learn.microsoft.com/dotnet/api/system.object) → `Asn1Util`

## Métodos

### `DecodeAs<T>(byte[])`

Decodes a byte array to an instance of a ASN1 decorated class

```csharp
public static T DecodeAs<T>(byte[] content)
```

**Parâmetros**

| Nome | Tipo | Descrição |
|---|---|---|
| `content` | [`byte[]`](https://learn.microsoft.com/dotnet/api/system.byte) | The ASN1 encoded content |

**Parâmetros de tipo**

| Nome | Descrição |
|---|---|
| `T` | The ASN1 attribute decorated class type to instantiate |

**Retorno**

`T` — An instance of T decoded

---

### `DecodeIA5String(byte[])`

Decodes an ASN1 IA5String primitive content to string

```csharp
public static string DecodeIA5String(byte[] content)
```

**Parâmetros**

| Nome | Tipo | Descrição |
|---|---|---|
| `content` | [`byte[]`](https://learn.microsoft.com/dotnet/api/system.byte) |  |

**Retorno**

[`string`](https://learn.microsoft.com/dotnet/api/system.string)

---

### `DecodeIntegerAsBigInteger(byte[])`

Decodes an ASN1 Integer primitive content as BigInteger

```csharp
public static BigInteger DecodeIntegerAsBigInteger(byte[] content)
```

**Parâmetros**

| Nome | Tipo | Descrição |
|---|---|---|
| `content` | [`byte[]`](https://learn.microsoft.com/dotnet/api/system.byte) |  |

**Retorno**

[`BigInteger`](https://learn.microsoft.com/dotnet/api/system.numerics.biginteger)

---

### `DecodeIntegerAsInt32(byte[])`

Decodes an ASN1 Integer primitive content as int

```csharp
public static int DecodeIntegerAsInt32(byte[] content)
```

**Parâmetros**

| Nome | Tipo | Descrição |
|---|---|---|
| `content` | [`byte[]`](https://learn.microsoft.com/dotnet/api/system.byte) |  |

**Retorno**

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

---

### `DecodeObjectIdentifier(byte[])`

Decodes an ASN1 ObjectIdentifier primitive content to OID string

```csharp
public static string DecodeObjectIdentifier(byte[] content)
```

**Parâmetros**

| Nome | Tipo | Descrição |
|---|---|---|
| `content` | [`byte[]`](https://learn.microsoft.com/dotnet/api/system.byte) |  |

**Retorno**

[`string`](https://learn.microsoft.com/dotnet/api/system.string)

---

### `DecodeOctetString(byte[])`

Decodes an ASN1 OctetString primitive content to byte array

```csharp
public static byte[] DecodeOctetString(byte[] content)
```

**Parâmetros**

| Nome | Tipo | Descrição |
|---|---|---|
| `content` | [`byte[]`](https://learn.microsoft.com/dotnet/api/system.byte) |  |

**Retorno**

[`byte[]`](https://learn.microsoft.com/dotnet/api/system.byte)

---

### `DecodePrintableString(byte[])`

Decodes an ASN1 PrintableString primitive content to string

```csharp
public static string DecodePrintableString(byte[] content)
```

**Parâmetros**

| Nome | Tipo | Descrição |
|---|---|---|
| `content` | [`byte[]`](https://learn.microsoft.com/dotnet/api/system.byte) |  |

**Retorno**

[`string`](https://learn.microsoft.com/dotnet/api/system.string)

---

### `DecodeString(byte[])`

Decodes any of ASN1 string primitives content to string

```csharp
public static string DecodeString(byte[] content)
```

**Parâmetros**

| Nome | Tipo | Descrição |
|---|---|---|
| `content` | [`byte[]`](https://learn.microsoft.com/dotnet/api/system.byte) |  |

**Retorno**

[`string`](https://learn.microsoft.com/dotnet/api/system.string)

---

### `DecodeUtcTimeAsDateTime(byte[])`

Decodes an ASN1 UTCTime primitive content as DateTime

```csharp
public static DateTime DecodeUtcTimeAsDateTime(byte[] content)
```

**Parâmetros**

| Nome | Tipo | Descrição |
|---|---|---|
| `content` | [`byte[]`](https://learn.microsoft.com/dotnet/api/system.byte) |  |

**Retorno**

[`DateTime`](https://learn.microsoft.com/dotnet/api/system.datetime)

---

### `DecodeUtcTimeAsDateTimeOffset(byte[])`

Decodes an ASN1 UTCTime primitive content as DateTimeOffset

```csharp
public static DateTimeOffset DecodeUtcTimeAsDateTimeOffset(byte[] content)
```

**Parâmetros**

| Nome | Tipo | Descrição |
|---|---|---|
| `content` | [`byte[]`](https://learn.microsoft.com/dotnet/api/system.byte) |  |

**Retorno**

[`DateTimeOffset`](https://learn.microsoft.com/dotnet/api/system.datetimeoffset)

---

### `DecodeUtf8String(byte[])`

Decodes an ASN1 UTF8String primitive content to string

```csharp
public static string DecodeUtf8String(byte[] content)
```

**Parâmetros**

| Nome | Tipo | Descrição |
|---|---|---|
| `content` | [`byte[]`](https://learn.microsoft.com/dotnet/api/system.byte) |  |

**Retorno**

[`string`](https://learn.microsoft.com/dotnet/api/system.string)

---

### `DerEncode(object)`

Encodes an ASN1 attribute decorated class instance to DER

```csharp
public static byte[] DerEncode(object obj)
```

**Parâmetros**

| Nome | Tipo | Descrição |
|---|---|---|
| `obj` | [`object`](https://learn.microsoft.com/dotnet/api/system.object) | The instance of a ASN1 class |

**Retorno**

[`byte[]`](https://learn.microsoft.com/dotnet/api/system.byte) — The DER encoded content

---

### `DerEncodeIA5String(string)`

Encodes a string to ASN1 DER IA5String

```csharp
public static byte[] DerEncodeIA5String(string s)
```

**Parâmetros**

| Nome | Tipo | Descrição |
|---|---|---|
| `s` | [`string`](https://learn.microsoft.com/dotnet/api/system.string) |  |

**Retorno**

[`byte[]`](https://learn.microsoft.com/dotnet/api/system.byte)

---

### `DerEncodeInteger(BigInteger)`

Encodes a BigInteger to ASN1 DER Integer

```csharp
public static byte[] DerEncodeInteger(BigInteger i)
```

**Parâmetros**

| Nome | Tipo | Descrição |
|---|---|---|
| `i` | [`BigInteger`](https://learn.microsoft.com/dotnet/api/system.numerics.biginteger) |  |

**Retorno**

[`byte[]`](https://learn.microsoft.com/dotnet/api/system.byte)

---

### `DerEncodeInteger(int)`

Encodes an int to ASN1 DER Integer

```csharp
public static byte[] DerEncodeInteger(int i)
```

**Parâmetros**

| Nome | Tipo | Descrição |
|---|---|---|
| `i` | [`int`](https://learn.microsoft.com/dotnet/api/system.int32) |  |

**Retorno**

[`byte[]`](https://learn.microsoft.com/dotnet/api/system.byte)

---

### `DerEncodeObjectIdentifier(string)`

Encodes an OID string to ASN1 DER ObjectIdentifier

```csharp
public static byte[] DerEncodeObjectIdentifier(string oid)
```

**Parâmetros**

| Nome | Tipo | Descrição |
|---|---|---|
| `oid` | [`string`](https://learn.microsoft.com/dotnet/api/system.string) |  |

**Retorno**

[`byte[]`](https://learn.microsoft.com/dotnet/api/system.byte)

---

### `DerEncodeOctetString(byte[])`

Encodes a byte array to ASN1 DER OctetString

```csharp
public static byte[] DerEncodeOctetString(byte[] octetString)
```

**Parâmetros**

| Nome | Tipo | Descrição |
|---|---|---|
| `octetString` | [`byte[]`](https://learn.microsoft.com/dotnet/api/system.byte) |  |

**Retorno**

[`byte[]`](https://learn.microsoft.com/dotnet/api/system.byte)

---

### `DerEncodePrintableString(string)`

Encodes a string to ASN1 DER PrintableString

```csharp
public static byte[] DerEncodePrintableString(string s)
```

**Parâmetros**

| Nome | Tipo | Descrição |
|---|---|---|
| `s` | [`string`](https://learn.microsoft.com/dotnet/api/system.string) |  |

**Retorno**

[`byte[]`](https://learn.microsoft.com/dotnet/api/system.byte)

---

### `DerEncodeUtcTime(DateTime)`

Encodes a DateTime to ASN1 DER UTCTime

```csharp
public static byte[] DerEncodeUtcTime(DateTime time)
```

**Parâmetros**

| Nome | Tipo | Descrição |
|---|---|---|
| `time` | [`DateTime`](https://learn.microsoft.com/dotnet/api/system.datetime) |  |

**Retorno**

[`byte[]`](https://learn.microsoft.com/dotnet/api/system.byte)

---

### `DerEncodeUtcTime(DateTimeOffset)`

Encodes a DateTimeOffset to ASN1 DER UTCTime

```csharp
public static byte[] DerEncodeUtcTime(DateTimeOffset time)
```

**Parâmetros**

| Nome | Tipo | Descrição |
|---|---|---|
| `time` | [`DateTimeOffset`](https://learn.microsoft.com/dotnet/api/system.datetimeoffset) |  |

**Retorno**

[`byte[]`](https://learn.microsoft.com/dotnet/api/system.byte)

---

### `DerEncodeUtf8String(string)`

Encodes a string to ASN1 DER UTF8String

```csharp
public static byte[] DerEncodeUtf8String(string s)
```

**Parâmetros**

| Nome | Tipo | Descrição |
|---|---|---|
| `s` | [`string`](https://learn.microsoft.com/dotnet/api/system.string) |  |

**Retorno**

[`byte[]`](https://learn.microsoft.com/dotnet/api/system.byte)

---

## Membros herdados

[`ToString()`](https://learn.microsoft.com/dotnet/api/system.object.tostring), [`Equals(object)`](<https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)>), [`Equals(object, object)`](<https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)>), [`ReferenceEquals(object, object)`](https://learn.microsoft.com/dotnet/api/system.object.referenceequals), [`GetHashCode()`](https://learn.microsoft.com/dotnet/api/system.object.gethashcode), [`GetType()`](https://learn.microsoft.com/dotnet/api/system.object.gettype), [`MemberwiseClone()`](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone)
