> ## Documentation Index
> Fetch the complete documentation index at: https://klef.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# WebhookVerification

> Checks that a request a vendor sent is the vendor's.

```csharp
public static class WebhookVerification
```

## Methods

### Decode()

```csharp
public static byte[]? Decode(SignatureEncoding encoding, string? claimed)
```

Decodes a signature, or answers [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) when it is missing or not in `encoding`.

#### Parameters

**encoding** `SignatureEncoding` *required*

**claimed** `string` *required*

#### Returns

`byte[]`

### Hmac()

```csharp
public static byte[] Hmac(HmacAlgorithm algorithm, string secret, ReadOnlySpan<byte> content)
```

Signs `content` with the UTF-8 bytes of `secret`.

#### Parameters

**algorithm** `HmacAlgorithm` *required*

**secret** `string` *required*

**content** `ReadOnlySpan\<byte\>` *required*

#### Returns

`byte[]`

### IsFresh()

```csharp
public static bool IsFresh(Instant signedAt, Instant now, Duration tolerance)
```

Checks that a signed timestamp lies within `tolerance` of `now`, either side.

#### Parameters

**signedAt** `Instant` *required*

**now** `Instant` *required*

**tolerance** `Duration` *required*

#### Returns

`bool`

### Matches()

```csharp
public static bool Matches(ReadOnlySpan<byte> expected, ReadOnlySpan<byte> claimed)
```

Compares two signatures in the same time however much of them matches.

#### Parameters

**expected** `ReadOnlySpan\<byte\>` *required*

**claimed** `ReadOnlySpan\<byte\>` *required*

#### Returns

`bool`

### VerifyEcdsa()

```csharp
public static bool VerifyEcdsa(string publicKey, ReadOnlySpan<byte> content, ReadOnlySpan<byte> signature, HashAlgorithmName hash, DSASignatureFormat format = DSASignatureFormat.IeeeP1363FixedFieldConcatenation)
```

Checks an ECDSA `signature` of `content` against the vendor's PEM `publicKey`.

#### Parameters

**publicKey** `string` *required*

**content** `ReadOnlySpan\<byte\>` *required*

**signature** `ReadOnlySpan\<byte\>` *required*

**hash** `HashAlgorithmName` *required*

**format** `DSASignatureFormat`

#### Returns

`bool`

### VerifyHmac()

```csharp
public static bool VerifyHmac(HmacAlgorithm algorithm, string? secret, ReadOnlySpan<byte> content, string? claimed, SignatureEncoding encoding)
```

Checks that `claimed` is the HMAC of `content` under `secret`.

#### Parameters

**algorithm** `HmacAlgorithm` *required*

**secret** `string` *required*

**content** `ReadOnlySpan\<byte\>` *required*

**claimed** `string` *required*

The signature the request carries, trimmed of surrounding space.

**encoding** `SignatureEncoding` *required*

#### Returns

`bool`

[true](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if it is; otherwise, [false](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool), as it is for an empty secret and a missing or undecodable claim. The comparison takes the same time however much matches (rule E6).

### VerifyRsa()

```csharp
public static bool VerifyRsa(string publicKey, ReadOnlySpan<byte> content, ReadOnlySpan<byte> signature, HashAlgorithmName hash)
```

Checks an RSA PKCS #1 v1.5 `signature` of `content` against the vendor's PEM `publicKey`.

#### Parameters

**publicKey** `string` *required*

**content** `ReadOnlySpan\<byte\>` *required*

**signature** `ReadOnlySpan\<byte\>` *required*

**hash** `HashAlgorithmName` *required*

#### Returns

`bool`


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.