1
0
mirror of https://github.com/XFox111/SimpleOTP.git synced 2026-04-22 08:00:45 +03:00

Added SimpleOTP API reference

2024-09-18 16:16:09 +03:00
parent 69da15bcc1
commit 38c05a6dd9
23 changed files with 3517 additions and 110 deletions
+21 -21
@@ -1,33 +1,33 @@
## EugeneFox.SimpleOTP package
- **SimpleOTP**
- [HashAlgorithmProviders](./simpleotp.hashalgorithmproviders.md)
- [Hotp](./simpleotp.hotp.md)
- [Otp](./simpleotp.otp.md)
- [OtpAlgorithm](./simpleotp.otpalgorithm.md)
- [OtpCode](./simpleotp.otpcode.md)
- [OtpConfig](./simpleotp.otpconfig.md)
- [OtpSecret](./simpleotp.otpsecret.md)
- [OtpType](./simpleotp.otptype.md)
- [OtpUriFormat](./simpleotp.otpuriformat.md)
- [ToleranceSpan](./simpleotp.tolerancespan.md)
- [Totp](./simpleotp.totp.md)
- [HashAlgorithmProviders](./simpleotp.hashalgorithmproviders)
- [Hotp](./simpleotp.hotp)
- [Otp](./simpleotp.otp)
- [OtpAlgorithm](./simpleotp.otpalgorithm)
- [OtpCode](./simpleotp.otpcode)
- [OtpConfig](./simpleotp.otpconfig)
- [OtpSecret](./simpleotp.otpsecret)
- [OtpType](./simpleotp.otptype)
- [OtpUriFormat](./simpleotp.otpuriformat)
- [ToleranceSpan](./simpleotp.tolerancespan)
- [Totp](./simpleotp.totp)
- **SimpleOTP.Converters**
- [OtpAlgorithmJsonConverter](./simpleotp.converters.otpalgorithmjsonconverter.md)
- [OtpCodeJsonConverter](./simpleotp.converters.otpcodejsonconverter.md)
- [OtpConfigJsonConverter](./simpleotp.converters.otpconfigjsonconverter.md)
- [OtpSecretJsonConverter](./simpleotp.converters.otpsecretjsonconverter.md)
- [OtpAlgorithmJsonConverter](./simpleotp.converters.otpalgorithmjsonconverter)
- [OtpCodeJsonConverter](./simpleotp.converters.otpcodejsonconverter)
- [OtpConfigJsonConverter](./simpleotp.converters.otpconfigjsonconverter)
- [OtpSecretJsonConverter](./simpleotp.converters.otpsecretjsonconverter)
- **SimpleOTP.Encoding**
- [Base32Encoder](./simpleotp.encoding.base32encoder.md)
- [IEncoder](./simpleotp.encoding.iencoder.md)
- [Base32Encoder](./simpleotp.encoding.base32encoder)
- [IEncoder](./simpleotp.encoding.iencoder)
- **SimpleOTP.Fluent**
- [OtpBuilder](./simpleotp.fluent.otpbuilder.md)
- [OtpConfigBuilder](./simpleotp.fluent.otpconfigbuilder.md)
- [OtpConfigFluentExtensions](./simpleotp.fluent.otpconfigfluentextensions.md)
- [OtpFluentExtensions](./simpleotp.fluent.otpfluentextensions.md)
- [OtpBuilder](./simpleotp.fluent.otpbuilder)
- [OtpConfigBuilder](./simpleotp.fluent.otpconfigbuilder)
- [OtpConfigFluentExtensions](./simpleotp.fluent.otpconfigfluentextensions)
- [OtpFluentExtensions](./simpleotp.fluent.otpfluentextensions)
## EugeneFox.SimpleOTP.DependencyInjection package
-89
@@ -1,89 +0,0 @@
Namespace: SimpleOTP
Provides methods for registering and retrieving providers.
```csharp
public static class HashAlgorithmProviders
```
Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [HashAlgorithmProviders](./simpleotp.hashalgorithmproviders.md)<br>
Attributes [NullableContextAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullablecontextattribute), [NullableAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullableattribute)
## Methods
### **AddProvider(OtpAlgorithm, KeyedHashAlgorithm)**
Registers a new provider.
```csharp
public static void AddProvider(OtpAlgorithm algorithm, KeyedHashAlgorithm algorithmProvider)
```
#### Parameters
`algorithm` [OtpAlgorithm](./simpleotp.otpalgorithm.md)<br>
The algorithm to register.
`algorithmProvider` KeyedHashAlgorithm<br>
The provider to register.
### **GetProvider(OtpAlgorithm)**
Retrieves a provider.
```csharp
public static KeyedHashAlgorithm GetProvider(OtpAlgorithm algorithm)
```
#### Parameters
`algorithm` [OtpAlgorithm](./simpleotp.otpalgorithm.md)<br>
The algorithm to retrieve.
#### Returns
KeyedHashAlgorithm<br>
The provider, or `null` if not found.
### **RemoveProvider(OtpAlgorithm)**
Removes a provider.
```csharp
public static void RemoveProvider(OtpAlgorithm algorithm)
```
#### Parameters
`algorithm` [OtpAlgorithm](./simpleotp.otpalgorithm.md)<br>
The algorithm to remove.
### **IsRegistered(OtpAlgorithm)**
Determines whether a provider is registered.
```csharp
public static bool IsRegistered(OtpAlgorithm algorithm)
```
#### Parameters
`algorithm` [OtpAlgorithm](./simpleotp.otpalgorithm.md)<br>
The algorithm to check.
#### Returns
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
`true` if the provider is registered; otherwise, `false`.
### **ClearProviders()**
Removes all registered providers.
```csharp
public static void ClearProviders()
```
**Remarks:**
This method also clears default providers. Use with caution.
+51
@@ -0,0 +1,51 @@
# SimpleOTP
## SimpleOTP
[HashAlgorithmProviders](./simpleotp.hashalgorithmproviders)
[Hotp](./simpleotp.hotp)
[Otp](./simpleotp.otp)
[OtpAlgorithm](./simpleotp.otpalgorithm)
[OtpCode](./simpleotp.otpcode)
[OtpConfig](./simpleotp.otpconfig)
[OtpSecret](./simpleotp.otpsecret)
[OtpType](./simpleotp.otptype)
[OtpUriFormat](./simpleotp.otpuriformat)
[ToleranceSpan](./simpleotp.tolerancespan)
[Totp](./simpleotp.totp)
## SimpleOTP.Converters
[OtpAlgorithmJsonConverter](./simpleotp.converters.otpalgorithmjsonconverter)
[OtpCodeJsonConverter](./simpleotp.converters.otpcodejsonconverter)
[OtpConfigJsonConverter](./simpleotp.converters.otpconfigjsonconverter)
[OtpSecretJsonConverter](./simpleotp.converters.otpsecretjsonconverter)
## SimpleOTP.Encoding
[Base32Encoder](./simpleotp.encoding.base32encoder)
[IEncoder](./simpleotp.encoding.iencoder)
## SimpleOTP.Fluent
[OtpBuilder](./simpleotp.fluent.otpbuilder)
[OtpConfigBuilder](./simpleotp.fluent.otpconfigbuilder)
[OtpConfigFluentExtensions](./simpleotp.fluent.otpconfigfluentextensions)
[OtpFluentExtensions](./simpleotp.fluent.otpfluentextensions)
+76
@@ -0,0 +1,76 @@
# OtpAlgorithmJsonConverter
Namespace: SimpleOTP.Converters
Provides a JSON converter for [OtpAlgorithm](simpleotp.otpalgorithm).
```csharp
public class OtpAlgorithmJsonConverter : System.Text.Json.Serialization.JsonConverter`1[[SimpleOTP.OtpAlgorithm, SimpleOTP, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]]
```
Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → JsonConverter → JsonConverter&lt;OtpAlgorithm&gt; → [OtpAlgorithmJsonConverter](simpleotp.converters.otpalgorithmjsonconverter)<br>
Attributes [NullableContextAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullablecontextattribute), [NullableAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullableattribute)
## Properties
### **HandleNull**
```csharp
public bool HandleNull { get; }
```
#### Property Value
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
### **Type**
```csharp
public Type Type { get; }
```
#### Property Value
[Type](https://docs.microsoft.com/en-us/dotnet/api/system.type)<br>
## Constructors
### **OtpAlgorithmJsonConverter()**
```csharp
public OtpAlgorithmJsonConverter()
```
## Methods
### **Read(Utf8JsonReader&, Type, JsonSerializerOptions)**
```csharp
public OtpAlgorithm Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
```
#### Parameters
`reader` Utf8JsonReader&<br>
`typeToConvert` [Type](https://docs.microsoft.com/en-us/dotnet/api/system.type)<br>
`options` JsonSerializerOptions<br>
#### Returns
[OtpAlgorithm](simpleotp.otpalgorithm)<br>
### **Write(Utf8JsonWriter, OtpAlgorithm, JsonSerializerOptions)**
```csharp
public void Write(Utf8JsonWriter writer, OtpAlgorithm value, JsonSerializerOptions options)
```
#### Parameters
`writer` Utf8JsonWriter<br>
`value` [OtpAlgorithm](simpleotp.otpalgorithm)<br>
`options` JsonSerializerOptions<br>
+76
@@ -0,0 +1,76 @@
# OtpCodeJsonConverter
Namespace: SimpleOTP.Converters
Provides a JSON converter for [OtpCode](simpleotp.otpcode).
```csharp
public class OtpCodeJsonConverter : System.Text.Json.Serialization.JsonConverter`1[[SimpleOTP.OtpCode, SimpleOTP, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]]
```
Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → JsonConverter → JsonConverter&lt;OtpCode&gt; → [OtpCodeJsonConverter](simpleotp.converters.otpcodejsonconverter)<br>
Attributes [NullableContextAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullablecontextattribute), [NullableAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullableattribute)
## Properties
### **HandleNull**
```csharp
public bool HandleNull { get; }
```
#### Property Value
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
### **Type**
```csharp
public Type Type { get; }
```
#### Property Value
[Type](https://docs.microsoft.com/en-us/dotnet/api/system.type)<br>
## Constructors
### **OtpCodeJsonConverter()**
```csharp
public OtpCodeJsonConverter()
```
## Methods
### **Read(Utf8JsonReader&, Type, JsonSerializerOptions)**
```csharp
public OtpCode Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
```
#### Parameters
`reader` Utf8JsonReader&<br>
`typeToConvert` [Type](https://docs.microsoft.com/en-us/dotnet/api/system.type)<br>
`options` JsonSerializerOptions<br>
#### Returns
[OtpCode](simpleotp.otpcode)<br>
### **Write(Utf8JsonWriter, OtpCode, JsonSerializerOptions)**
```csharp
public void Write(Utf8JsonWriter writer, OtpCode value, JsonSerializerOptions options)
```
#### Parameters
`writer` Utf8JsonWriter<br>
`value` [OtpCode](simpleotp.otpcode)<br>
`options` JsonSerializerOptions<br>
+76
@@ -0,0 +1,76 @@
# OtpConfigJsonConverter
Namespace: SimpleOTP.Converters
Provides a JSON converter for [OtpConfig](simpleotp.otpconfig).
```csharp
public class OtpConfigJsonConverter : System.Text.Json.Serialization.JsonConverter`1[[SimpleOTP.OtpConfig, SimpleOTP, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]]
```
Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → JsonConverter → JsonConverter&lt;OtpConfig&gt; → [OtpConfigJsonConverter](simpleotp.converters.otpconfigjsonconverter)<br>
Attributes [NullableContextAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullablecontextattribute), [NullableAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullableattribute)
## Properties
### **HandleNull**
```csharp
public bool HandleNull { get; }
```
#### Property Value
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
### **Type**
```csharp
public Type Type { get; }
```
#### Property Value
[Type](https://docs.microsoft.com/en-us/dotnet/api/system.type)<br>
## Constructors
### **OtpConfigJsonConverter()**
```csharp
public OtpConfigJsonConverter()
```
## Methods
### **Read(Utf8JsonReader&, Type, JsonSerializerOptions)**
```csharp
public OtpConfig Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
```
#### Parameters
`reader` Utf8JsonReader&<br>
`typeToConvert` [Type](https://docs.microsoft.com/en-us/dotnet/api/system.type)<br>
`options` JsonSerializerOptions<br>
#### Returns
[OtpConfig](simpleotp.otpconfig)<br>
### **Write(Utf8JsonWriter, OtpConfig, JsonSerializerOptions)**
```csharp
public void Write(Utf8JsonWriter writer, OtpConfig value, JsonSerializerOptions options)
```
#### Parameters
`writer` Utf8JsonWriter<br>
`value` [OtpConfig](simpleotp.otpconfig)<br>
`options` JsonSerializerOptions<br>
+76
@@ -0,0 +1,76 @@
# OtpSecretJsonConverter
Namespace: SimpleOTP.Converters
Provides a JSON converter for [OtpSecret](simpleotp.otpsecret).
```csharp
public class OtpSecretJsonConverter : System.Text.Json.Serialization.JsonConverter`1[[SimpleOTP.OtpSecret, SimpleOTP, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]]
```
Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → JsonConverter → JsonConverter&lt;OtpSecret&gt; → [OtpSecretJsonConverter](simpleotp.converters.otpsecretjsonconverter)<br>
Attributes [NullableContextAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullablecontextattribute), [NullableAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullableattribute)
## Properties
### **HandleNull**
```csharp
public bool HandleNull { get; }
```
#### Property Value
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
### **Type**
```csharp
public Type Type { get; }
```
#### Property Value
[Type](https://docs.microsoft.com/en-us/dotnet/api/system.type)<br>
## Constructors
### **OtpSecretJsonConverter()**
```csharp
public OtpSecretJsonConverter()
```
## Methods
### **Read(Utf8JsonReader&, Type, JsonSerializerOptions)**
```csharp
public OtpSecret Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
```
#### Parameters
`reader` Utf8JsonReader&<br>
`typeToConvert` [Type](https://docs.microsoft.com/en-us/dotnet/api/system.type)<br>
`options` JsonSerializerOptions<br>
#### Returns
[OtpSecret](simpleotp.otpsecret)<br>
### **Write(Utf8JsonWriter, OtpSecret, JsonSerializerOptions)**
```csharp
public void Write(Utf8JsonWriter writer, OtpSecret value, JsonSerializerOptions options)
```
#### Parameters
`writer` Utf8JsonWriter<br>
`value` [OtpSecret](simpleotp.otpsecret)<br>
`options` JsonSerializerOptions<br>
+146
@@ -0,0 +1,146 @@
# Base32Encoder
Namespace: SimpleOTP.Encoding
Provides methods for encoding and decoding data using the RFC 4648 Base32 standard alphabet.
```csharp
public class Base32Encoder : IEncoder
```
Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [Base32Encoder](simpleotp.encoding.base32encoder)<br>
Implements [IEncoder](simpleotp.encoding.iencoder)<br>
Attributes [NullableContextAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullablecontextattribute), [NullableAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullableattribute)
## Properties
### **Instance**
Gets the singleton instance of the [Base32Encoder](simpleotp.encoding.base32encoder) class.
```csharp
public static Base32Encoder Instance { get; }
```
#### Property Value
[Base32Encoder](simpleotp.encoding.base32encoder)<br>
### **Scheme**
```csharp
public string Scheme { get; }
```
#### Property Value
[String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
## Constructors
### **Base32Encoder()**
```csharp
public Base32Encoder()
```
## Methods
### **EncodeBytes(Byte[])**
Converts a byte array to a Base32 string representation.
```csharp
public string EncodeBytes(Byte[] bytes)
```
#### Parameters
`bytes` [Byte[]](https://docs.microsoft.com/en-us/dotnet/api/system.byte)<br>
The byte array to convert.
#### Returns
[String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The Base32 string representation of the byte array.
#### Exceptions
[ArgumentNullException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentnullexception)<br>
Thrown when parameter is null.
### **GetBytes(String)**
Converts a Base32 encoded string to a byte array.
```csharp
public Byte[] GetBytes(string inArray)
```
#### Parameters
`inArray` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The Base32 encoded string to convert.
#### Returns
[Byte[]](https://docs.microsoft.com/en-us/dotnet/api/system.byte)<br>
The byte array representation of the Base32 encoded string.
#### Exceptions
[ArgumentNullException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentnullexception)<br>
Thrown when parameter is null.
[ArgumentException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentexception)<br>
Thrown when `inArray` is empty, whitespace, or contains invalid characters.
**Remarks:**
Trailing bits are ignored (e.g. AAAR will be treated as AAAQ - 0x00 0x01).
### **CharToValue(Char)**
Converts a Base32 character to its numeric value.
```csharp
protected int CharToValue(char c)
```
#### Parameters
`c` [Char](https://docs.microsoft.com/en-us/dotnet/api/system.char)<br>
The Base32 character to convert.
#### Returns
[Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
The numeric value of the Base32 character.
#### Exceptions
[ArgumentException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentexception)<br>
Thrown when `c` is not a valid Base32 character.
### **ValueToChar(Int32)**
Converts a numeric value to its Base32 character.
```csharp
protected char ValueToChar(int value)
```
#### Parameters
`value` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
The numeric value to convert.
#### Returns
[Char](https://docs.microsoft.com/en-us/dotnet/api/system.char)<br>
The Base32 character corresponding to the numeric value.
#### Exceptions
[ArgumentException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentexception)<br>
Thrown when `value` is not a valid Base32 value.
+63
@@ -0,0 +1,63 @@
# IEncoder
Namespace: SimpleOTP.Encoding
Provides methods for encoding and decoding data using the RFC 4648 Base32 "Extended Hex" alphabet.
```csharp
public interface IEncoder
```
Attributes [NullableContextAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullablecontextattribute)
## Properties
### **Scheme**
Gets the encoding scheme used by the encoder (e.g. `base32` or `base32hex`).
```csharp
public abstract string Scheme { get; }
```
#### Property Value
[String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
## Methods
### **EncodeBytes(Byte[])**
Converts a byte array to a Base32 string representation.
```csharp
string EncodeBytes(Byte[] data)
```
#### Parameters
`data` [Byte[]](https://docs.microsoft.com/en-us/dotnet/api/system.byte)<br>
The byte array to convert.
#### Returns
[String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The Base32 string representation of the byte array.
### **GetBytes(String)**
Converts a Base32 encoded string to a byte array.
```csharp
Byte[] GetBytes(string data)
```
#### Parameters
`data` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The Base32 encoded string to convert.
#### Returns
[Byte[]](https://docs.microsoft.com/en-us/dotnet/api/system.byte)<br>
The byte array representation of the Base32 encoded string.
+68
@@ -0,0 +1,68 @@
# OtpBuilder
Namespace: SimpleOTP.Fluent
Class used to streamline OTP code generation on client devices.
```csharp
public static class OtpBuilder
```
Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [OtpBuilder](simpleotp.fluent.otpbuilder)<br>
Attributes [NullableContextAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullablecontextattribute), [NullableAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullableattribute)
## Methods
### **UseTotp(Int32)**
Use TOTP generator with optional counter period.
```csharp
public static Otp UseTotp(int period)
```
#### Parameters
`period` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
Period in seconds.
#### Returns
[Otp](simpleotp.otp)<br>
[Otp](simpleotp.otp) instance.
### **UseHotp(Int64)**
Use HOTP generator with optional counter value.
```csharp
public static Otp UseHotp(long counter)
```
#### Parameters
`counter` [Int64](https://docs.microsoft.com/en-us/dotnet/api/system.int64)<br>
Counter value.
#### Returns
[Otp](simpleotp.otp)<br>
[Otp](simpleotp.otp) instance.
### **FromConfig(OtpConfig)**
Creates [Otp](simpleotp.otp) instance from [OtpConfig](simpleotp.otpconfig) object.
```csharp
public static Otp FromConfig(OtpConfig config)
```
#### Parameters
`config` [OtpConfig](simpleotp.otpconfig)<br>
[OtpConfig](simpleotp.otpconfig) object.
#### Returns
[Otp](simpleotp.otp)<br>
[Otp](simpleotp.otp) instance.
+80
@@ -0,0 +1,80 @@
# OtpConfigBuilder
Namespace: SimpleOTP.Fluent
Class used to streamline OTP code configuration on client devices.
```csharp
public static class OtpConfigBuilder
```
Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [OtpConfigBuilder](simpleotp.fluent.otpconfigbuilder)<br>
Attributes [NullableContextAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullablecontextattribute), [NullableAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullableattribute)
## Methods
### **UseTotp(String, Int32)**
Use TOTP configuration with optional counter period.
```csharp
public static OtpConfig UseTotp(string accountName, int period)
```
#### Parameters
`accountName` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
Account name.
`period` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
Period in seconds.
#### Returns
[OtpConfig](simpleotp.otpconfig)<br>
[OtpConfig](simpleotp.otpconfig) instance.
### **UseHotp(String, Int64)**
Use HOTP configuration with optional counter.
```csharp
public static OtpConfig UseHotp(string accountName, long counter)
```
#### Parameters
`accountName` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
Account name.
`counter` [Int64](https://docs.microsoft.com/en-us/dotnet/api/system.int64)<br>
Counter value.
#### Returns
[OtpConfig](simpleotp.otpconfig)<br>
[OtpConfig](simpleotp.otpconfig) instance.
### **UseApple(String, String, String)**
Use TOTP which satisfies Apple's specification requirements.
```csharp
public static OtpConfig UseApple(string accountName, string issuerName, string issuerDomain)
```
#### Parameters
`accountName` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
Account name.
`issuerName` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
Issuer/application/service display name.
`issuerDomain` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
Issuer/application/service domain name.
#### Returns
[OtpConfig](simpleotp.otpconfig)<br>
[OtpConfig](simpleotp.otpconfig) instance.
+219
@@ -0,0 +1,219 @@
# OtpConfigFluentExtensions
Namespace: SimpleOTP.Fluent
Provides fluent API for configuring [OtpConfig](simpleotp.otpconfig) objects.
```csharp
public static class OtpConfigFluentExtensions
```
Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [OtpConfigFluentExtensions](simpleotp.fluent.otpconfigfluentextensions)<br>
Attributes [NullableContextAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullablecontextattribute), [NullableAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullableattribute), [ExtensionAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.extensionattribute)
## Methods
### **WithLabel(OtpConfig, String)**
Sets the [OtpConfig.Label](simpleotp.otpconfig#label) property.
```csharp
public static OtpConfig WithLabel(OtpConfig config, string label)
```
#### Parameters
`config` [OtpConfig](simpleotp.otpconfig)<br>
The [OtpConfig](simpleotp.otpconfig) object to configure.
`label` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The label of the OTP config.
#### Returns
[OtpConfig](simpleotp.otpconfig)<br>
The configured [OtpConfig](simpleotp.otpconfig) object.
### **WithIssuer(OtpConfig, String)**
Sets the [OtpConfig.Issuer](simpleotp.otpconfig#issuer) property.
```csharp
public static OtpConfig WithIssuer(OtpConfig config, string issuer)
```
#### Parameters
`config` [OtpConfig](simpleotp.otpconfig)<br>
The [OtpConfig](simpleotp.otpconfig) object to configure.
`issuer` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The issuer of the OTP config.
#### Returns
[OtpConfig](simpleotp.otpconfig)<br>
The configured [OtpConfig](simpleotp.otpconfig) object.
### **WithAppleIssuer(OtpConfig, String, String)**
Sets the issuer info, according to Apple specification.
```csharp
public static OtpConfig WithAppleIssuer(OtpConfig config, string displayName, string domain)
```
#### Parameters
`config` [OtpConfig](simpleotp.otpconfig)<br>
The [OtpConfig](simpleotp.otpconfig) object to configure.
`displayName` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The display name of the issuer.
`domain` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The domain name of the issuer.
#### Returns
[OtpConfig](simpleotp.otpconfig)<br>
### **WithNewSecret(OtpConfig, Int32)**
Sets the [OtpConfig.Secret](simpleotp.otpconfig#secret) property with a new secret.
```csharp
public static OtpConfig WithNewSecret(OtpConfig config, int bytesLength)
```
#### Parameters
`config` [OtpConfig](simpleotp.otpconfig)<br>
The [OtpConfig](simpleotp.otpconfig) object to configure.
`bytesLength` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
The length of the secret in bytes.
#### Returns
[OtpConfig](simpleotp.otpconfig)<br>
The configured [OtpConfig](simpleotp.otpconfig) object.
### **WithSecret(OtpConfig, OtpSecret)**
Sets the [OtpConfig.Secret](simpleotp.otpconfig#secret) property with specified secret.
```csharp
public static OtpConfig WithSecret(OtpConfig config, OtpSecret secret)
```
#### Parameters
`config` [OtpConfig](simpleotp.otpconfig)<br>
The [OtpConfig](simpleotp.otpconfig) object to configure.
`secret` [OtpSecret](simpleotp.otpsecret)<br>
The secret to use.
#### Returns
[OtpConfig](simpleotp.otpconfig)<br>
The configured [OtpConfig](simpleotp.otpconfig) object.
### **WithAlgorithm(OtpConfig, OtpAlgorithm)**
Sets the [OtpConfig.Algorithm](simpleotp.otpconfig#algorithm) property.
```csharp
public static OtpConfig WithAlgorithm(OtpConfig config, OtpAlgorithm algorithm)
```
#### Parameters
`config` [OtpConfig](simpleotp.otpconfig)<br>
The [OtpConfig](simpleotp.otpconfig) object to configure.
`algorithm` [OtpAlgorithm](simpleotp.otpalgorithm)<br>
The algorithm to use.
#### Returns
[OtpConfig](simpleotp.otpconfig)<br>
The configured [OtpConfig](simpleotp.otpconfig) object.
**Remarks:**
Not recommended for use, since most implementations do not support custom values.
### **WithDigits(OtpConfig, Int32)**
Sets the [OtpConfig.Digits](simpleotp.otpconfig#digits) property.
```csharp
public static OtpConfig WithDigits(OtpConfig config, int digits)
```
#### Parameters
`config` [OtpConfig](simpleotp.otpconfig)<br>
The [OtpConfig](simpleotp.otpconfig) object to configure.
`digits` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
The number of digits to use.
#### Returns
[OtpConfig](simpleotp.otpconfig)<br>
The configured [OtpConfig](simpleotp.otpconfig) object.
**Remarks:**
Not recommended for use, since most implementations do not support custom values.
### **AddCustomProperty(OtpConfig, String, String)**
Adds a custom vendor-specific property to the [OtpConfig](simpleotp.otpconfig).
```csharp
public static OtpConfig AddCustomProperty(OtpConfig config, string key, string value)
```
#### Parameters
`config` [OtpConfig](simpleotp.otpconfig)<br>
The [OtpConfig](simpleotp.otpconfig) object to configure.
`key` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The key of the property.
`value` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The value of the property.
#### Returns
[OtpConfig](simpleotp.otpconfig)<br>
The configured [OtpConfig](simpleotp.otpconfig) object.
**Remarks:**
If set, reserved keys
`issuer, digits, counter, secret, period and algorithm`
will be removed from the [OtpConfig.CustomProperties](simpleotp.otpconfig#customproperties) upon it's serialization to URI.
### **CreateGenerator(OtpConfig)**
Creates a new [Otp](simpleotp.otp) object from the provided [OtpConfig](simpleotp.otpconfig)
```csharp
public static Otp CreateGenerator(OtpConfig config)
```
#### Parameters
`config` [OtpConfig](simpleotp.otpconfig)<br>
The [OtpConfig](simpleotp.otpconfig) object to use.
#### Returns
[Otp](simpleotp.otp)<br>
A new [Otp](simpleotp.otp) object.
+98
@@ -0,0 +1,98 @@
# OtpFluentExtensions
Namespace: SimpleOTP.Fluent
Provides fluent API for configuring [Otp](simpleotp.otp) objects.
```csharp
public static class OtpFluentExtensions
```
Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [OtpFluentExtensions](simpleotp.fluent.otpfluentextensions)<br>
Attributes [NullableContextAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullablecontextattribute), [NullableAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullableattribute), [ExtensionAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.extensionattribute)
## Methods
### **WithNewSecret(Otp, Int32)**
Creates a new [Otp](simpleotp.otp) object from the provided [OtpConfig](simpleotp.otpconfig)
```csharp
public static Otp WithNewSecret(Otp generator, int bytesLength)
```
#### Parameters
`generator` [Otp](simpleotp.otp)<br>
The [Otp](simpleotp.otp) object to configure.
`bytesLength` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
The length of the secret in bytes.
#### Returns
[Otp](simpleotp.otp)<br>
The configured [Otp](simpleotp.otp) object.
### **WithSecret(Otp, OtpSecret)**
Creates a new [Otp](simpleotp.otp) object from the provided [OtpSecret](simpleotp.otpsecret)
```csharp
public static Otp WithSecret(Otp generator, OtpSecret secret)
```
#### Parameters
`generator` [Otp](simpleotp.otp)<br>
The [Otp](simpleotp.otp) object to configure.
`secret` [OtpSecret](simpleotp.otpsecret)<br>
The [OtpSecret](simpleotp.otpsecret) to use.
#### Returns
[Otp](simpleotp.otp)<br>
The configured [Otp](simpleotp.otp) object.
### **WithDigits(Otp, Int32)**
Sets the [Otp.Digits](simpleotp.otp#digits) property.
```csharp
public static Otp WithDigits(Otp generator, int digits)
```
#### Parameters
`generator` [Otp](simpleotp.otp)<br>
The [Otp](simpleotp.otp) object to configure.
`digits` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
The number of digits to use in OTP codes.
#### Returns
[Otp](simpleotp.otp)<br>
The configured [Otp](simpleotp.otp) object.
### **WithAlgorithm(Otp, OtpAlgorithm)**
Sets the [Otp.Algorithm](simpleotp.otp#algorithm) property.
```csharp
public static Otp WithAlgorithm(Otp generator, OtpAlgorithm algorithm)
```
#### Parameters
`generator` [Otp](simpleotp.otp)<br>
The [Otp](simpleotp.otp) object to configure.
`algorithm` [OtpAlgorithm](simpleotp.otpalgorithm)<br>
The algorithm to use.
#### Returns
[Otp](simpleotp.otp)<br>
The configured [Otp](simpleotp.otp) object.
+169
@@ -0,0 +1,169 @@
# Hotp
Namespace: SimpleOTP
Represents a HOTP (HMAC-based One-Time Password) generator.
```csharp
public class Hotp : Otp
```
Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [Otp](simpleotp.otp) → [Hotp](simpleotp.hotp)<br>
Attributes [NullableContextAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullablecontextattribute), [NullableAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullableattribute)
## Properties
### **Counter**
Gets or sets the counter value used for generating OTP codes.
```csharp
public long Counter { get; set; }
```
#### Property Value
[Int64](https://docs.microsoft.com/en-us/dotnet/api/system.int64)<br>
### **Secret**
Gets or sets the secret key used for generating OTPs.
```csharp
public OtpSecret Secret { get; set; }
```
#### Property Value
[OtpSecret](simpleotp.otpsecret)<br>
### **Algorithm**
Gets or sets the algorithm used for generating OTP codes.
```csharp
public OtpAlgorithm Algorithm { get; set; }
```
#### Property Value
[OtpAlgorithm](simpleotp.otpalgorithm)<br>
### **Digits**
Gets or sets the number of digits in the OTP code.
```csharp
public int Digits { get; set; }
```
#### Property Value
[Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
Default: 6. Recommended: 6-8.
## Constructors
### **Hotp(OtpSecret)**
Initializes a new instance of the [Hotp](simpleotp.hotp) class
```csharp
public Hotp(OtpSecret secret)
```
#### Parameters
`secret` [OtpSecret](simpleotp.otpsecret)<br>
The secret key used for generating OTP codes.
### **Hotp(OtpSecret, Int64)**
Initializes a new instance of the [Hotp](simpleotp.hotp) class
```csharp
public Hotp(OtpSecret secret, long counter)
```
#### Parameters
`secret` [OtpSecret](simpleotp.otpsecret)<br>
The secret key used for generating OTP codes.
`counter` [Int64](https://docs.microsoft.com/en-us/dotnet/api/system.int64)<br>
The counter value used for generating OTP codes.
### **Hotp(OtpSecret, Int64, Int32)**
Initializes a new instance of the [Hotp](simpleotp.hotp) class
```csharp
public Hotp(OtpSecret secret, long counter, int digits)
```
#### Parameters
`secret` [OtpSecret](simpleotp.otpsecret)<br>
The secret key used for generating OTP codes.
`counter` [Int64](https://docs.microsoft.com/en-us/dotnet/api/system.int64)<br>
The counter value used for generating OTP codes.
`digits` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
The number of digits in the OTP code.
### **Hotp(OtpSecret, Int64, OtpAlgorithm)**
Initializes a new instance of the [Hotp](simpleotp.hotp) class
```csharp
public Hotp(OtpSecret secret, long counter, OtpAlgorithm algorithm)
```
#### Parameters
`secret` [OtpSecret](simpleotp.otpsecret)<br>
The secret key used for generating OTP codes.
`counter` [Int64](https://docs.microsoft.com/en-us/dotnet/api/system.int64)<br>
The counter value used for generating OTP codes.
`algorithm` [OtpAlgorithm](simpleotp.otpalgorithm)<br>
The algorithm used for generating OTP codes.
### **Hotp(OtpSecret, Int64, OtpAlgorithm, Int32)**
Initializes a new instance of the [Hotp](simpleotp.hotp) class
```csharp
public Hotp(OtpSecret secret, long counter, OtpAlgorithm algorithm, int digits)
```
#### Parameters
`secret` [OtpSecret](simpleotp.otpsecret)<br>
The secret key used for generating OTP codes.
`counter` [Int64](https://docs.microsoft.com/en-us/dotnet/api/system.int64)<br>
The counter value used for generating OTP codes.
`algorithm` [OtpAlgorithm](simpleotp.otpalgorithm)<br>
The algorithm used for generating OTP codes.
`digits` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
The number of digits in the OTP code.
## Methods
### **GetCounter()**
Gets the current counter value.
```csharp
protected long GetCounter()
```
#### Returns
[Int64](https://docs.microsoft.com/en-us/dotnet/api/system.int64)<br>
The current counter value.
+326
@@ -0,0 +1,326 @@
# Otp
Namespace: SimpleOTP
Represents an abstract class for generating and validating One-Time Passwords (OTP).
```csharp
public abstract class Otp
```
Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [Otp](simpleotp.otp)<br>
Attributes [NullableContextAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullablecontextattribute), [NullableAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullableattribute)
## Properties
### **Secret**
Gets or sets the secret key used for generating OTPs.
```csharp
public OtpSecret Secret { get; set; }
```
#### Property Value
[OtpSecret](simpleotp.otpsecret)<br>
### **Algorithm**
Gets or sets the algorithm used for generating OTP codes.
```csharp
public OtpAlgorithm Algorithm { get; set; }
```
#### Property Value
[OtpAlgorithm](simpleotp.otpalgorithm)<br>
### **Digits**
Gets or sets the number of digits in the OTP code.
```csharp
public int Digits { get; set; }
```
#### Property Value
[Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
Default: 6. Recommended: 6-8.
## Constructors
### **Otp(OtpSecret, OtpAlgorithm, Int32)**
Initializes a new instance of the [Otp](simpleotp.otp) class.
```csharp
public Otp(OtpSecret secret, OtpAlgorithm algorithm, int digits)
```
#### Parameters
`secret` [OtpSecret](simpleotp.otpsecret)<br>
The secret key used for generating OTP codes.
`algorithm` [OtpAlgorithm](simpleotp.otpalgorithm)<br>
The algorithm used for generating OTP codes.
`digits` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
The number of digits in the OTP code.
### **Otp(OtpSecret, OtpAlgorithm)**
Initializes a new instance of the [Otp](simpleotp.otp) class.
```csharp
public Otp(OtpSecret secret, OtpAlgorithm algorithm)
```
#### Parameters
`secret` [OtpSecret](simpleotp.otpsecret)<br>
The secret key used for generating OTP codes.
`algorithm` [OtpAlgorithm](simpleotp.otpalgorithm)<br>
The algorithm used for generating OTP codes.
### **Otp(OtpSecret, Int32)**
Initializes a new instance of the [Otp](simpleotp.otp) class.
```csharp
public Otp(OtpSecret secret, int digits)
```
#### Parameters
`secret` [OtpSecret](simpleotp.otpsecret)<br>
The secret key used for generating OTP codes.
`digits` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
The number of digits in the OTP code.
### **Otp(OtpSecret)**
Initializes a new instance of the [Otp](simpleotp.otp) class.
```csharp
public Otp(OtpSecret secret)
```
#### Parameters
`secret` [OtpSecret](simpleotp.otpsecret)<br>
The secret key used for generating OTP codes.
## Methods
### **Generate()**
Generates an OTP code.
```csharp
public OtpCode Generate()
```
#### Returns
[OtpCode](simpleotp.otpcode)<br>
The generated OTP code.
### **Generate(Int64)**
Generates an OTP code for the specified counter value.
```csharp
public OtpCode Generate(long counter)
```
#### Parameters
`counter` [Int64](https://docs.microsoft.com/en-us/dotnet/api/system.int64)<br>
The counter value to generate the OTP code for.
#### Returns
[OtpCode](simpleotp.otpcode)<br>
The generated OTP code.
### **Validate(OtpCode)**
Validates an OTP code.
```csharp
public bool Validate(OtpCode code)
```
#### Parameters
`code` [OtpCode](simpleotp.otpcode)<br>
The OTP code to validate.
#### Returns
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
`true` if the OTP code is valid; otherwise, `false`.
#### Exceptions
[InvalidOperationException](https://docs.microsoft.com/en-us/dotnet/api/system.invalidoperationexception)<br>
Implementation for the [Otp.Algorithm](simpleotp.otp#algorithm) algorithm was not found.
Use [HashAlgorithmProviders.AddProvider(OtpAlgorithm, KeyedHashAlgorithm)](simpleotp.hashalgorithmproviders#addproviderotpalgorithm-keyedhashalgorithm) to register an implementation.
### **Validate(OtpCode, ToleranceSpan)**
Validates an OTP code with tolerance.
```csharp
public bool Validate(OtpCode code, ToleranceSpan tolerance)
```
#### Parameters
`code` [OtpCode](simpleotp.otpcode)<br>
The OTP code to validate.
`tolerance` [ToleranceSpan](simpleotp.tolerancespan)<br>
The tolerance span for code validation.
#### Returns
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
`true` if the OTP code is valid; otherwise, `false`.
#### Exceptions
[InvalidOperationException](https://docs.microsoft.com/en-us/dotnet/api/system.invalidoperationexception)<br>
Implementation for the [Otp.Algorithm](simpleotp.otp#algorithm) algorithm was not found.
Use [HashAlgorithmProviders.AddProvider(OtpAlgorithm, KeyedHashAlgorithm)](simpleotp.hashalgorithmproviders#addproviderotpalgorithm-keyedhashalgorithm) to register an implementation.
### **Validate(OtpCode, ToleranceSpan, Int32&)**
Validates an OTP code with tolerance and returns the resynchronization value.
```csharp
public bool Validate(OtpCode code, ToleranceSpan tolerance, Int32& resyncValue)
```
#### Parameters
`code` [OtpCode](simpleotp.otpcode)<br>
The OTP code to validate.
`tolerance` [ToleranceSpan](simpleotp.tolerancespan)<br>
The tolerance span for code validation.
`resyncValue` [Int32&](https://docs.microsoft.com/en-us/dotnet/api/system.int32&)<br>
The resynchronization value. Indicates how much given OTP code is ahead or behind the current counter value.
#### Returns
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
`true` if the OTP code is valid; otherwise, `false`.
#### Exceptions
[InvalidOperationException](https://docs.microsoft.com/en-us/dotnet/api/system.invalidoperationexception)<br>
Implementation for the [Otp.Algorithm](simpleotp.otp#algorithm) algorithm was not found.
Use [HashAlgorithmProviders.AddProvider(OtpAlgorithm, KeyedHashAlgorithm)](simpleotp.hashalgorithmproviders#addproviderotpalgorithm-keyedhashalgorithm) to register an implementation.
### **Validate(OtpCode, ToleranceSpan, Int64, Int32&)**
Validates an OTP code with tolerance and base counter value, and returns the resynchronization value.
```csharp
public bool Validate(OtpCode code, ToleranceSpan tolerance, long baseCounter, Int32& resyncValue)
```
#### Parameters
`code` [OtpCode](simpleotp.otpcode)<br>
The OTP code to validate.
`tolerance` [ToleranceSpan](simpleotp.tolerancespan)<br>
The tolerance span for code validation.
`baseCounter` [Int64](https://docs.microsoft.com/en-us/dotnet/api/system.int64)<br>
The base counter value.
`resyncValue` [Int32&](https://docs.microsoft.com/en-us/dotnet/api/system.int32&)<br>
The resynchronization value. Indicates how much given OTP code is ahead or behind the current counter value.
#### Returns
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
`true` if the OTP code is valid; otherwise, `false`.
#### Exceptions
[InvalidOperationException](https://docs.microsoft.com/en-us/dotnet/api/system.invalidoperationexception)<br>
Implementation for the [Otp.Algorithm](simpleotp.otp#algorithm) algorithm was not found.
Use [HashAlgorithmProviders.AddProvider(OtpAlgorithm, KeyedHashAlgorithm)](simpleotp.hashalgorithmproviders#addproviderotpalgorithm-keyedhashalgorithm) to register an implementation.
### **GetCounter()**
Gets the current counter value.
```csharp
protected abstract long GetCounter()
```
#### Returns
[Int64](https://docs.microsoft.com/en-us/dotnet/api/system.int64)<br>
The current counter value.
### **Compute(Int64)**
Computes the OTP code for the specified counter value.
```csharp
protected int Compute(long counter)
```
#### Parameters
`counter` [Int64](https://docs.microsoft.com/en-us/dotnet/api/system.int64)<br>
The counter value to compute the OTP code for.
#### Returns
[Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
The OTP code for the specified counter value.
#### Exceptions
[InvalidOperationException](https://docs.microsoft.com/en-us/dotnet/api/system.invalidoperationexception)<br>
Implementation for the [Otp.Algorithm](simpleotp.otp#algorithm) algorithm was not found.
Use [HashAlgorithmProviders.AddProvider(OtpAlgorithm, KeyedHashAlgorithm)](simpleotp.hashalgorithmproviders#addproviderotpalgorithm-keyedhashalgorithm) to register an implementation.
### **Compute(Int64, KeyedHashAlgorithm)**
Computes the OTP code for the specified counter value using provided hash algorithm.
```csharp
protected int Compute(long counter, KeyedHashAlgorithm hashAlgorithm)
```
#### Parameters
`counter` [Int64](https://docs.microsoft.com/en-us/dotnet/api/system.int64)<br>
The counter value to compute the OTP code for.
`hashAlgorithm` KeyedHashAlgorithm<br>
The hash algorithm to use for computing the OTP code.
#### Returns
[Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
The OTP code for the specified counter value.
**Remarks:**
You need to dispose of the `hashAlgorithm` object yourself when you are done using it.
+236
@@ -0,0 +1,236 @@
# OtpAlgorithm
Namespace: SimpleOTP
Represents the hashing algorithm used for One-Time Passwords.
```csharp
public struct OtpAlgorithm
```
Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [ValueType](https://docs.microsoft.com/en-us/dotnet/api/system.valuetype) → [OtpAlgorithm](simpleotp.otpalgorithm)<br>
Implements [IEquatable&lt;OtpAlgorithm&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.iequatable-1), [IEquatable&lt;String&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.iequatable-1), IXmlSerializable<br>
Attributes [SerializableAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.serializableattribute), [NullableContextAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullablecontextattribute), [NullableAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullableattribute), [IsReadOnlyAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.isreadonlyattribute), JsonConverterAttribute
## Properties
### **SHA1**
The HMAC-SHA1 hashing algorithm.
```csharp
public static OtpAlgorithm SHA1 { get; }
```
#### Property Value
[OtpAlgorithm](simpleotp.otpalgorithm)<br>
### **SHA256**
The HMAC-SHA256 hashing algorithm.
```csharp
public static OtpAlgorithm SHA256 { get; }
```
#### Property Value
[OtpAlgorithm](simpleotp.otpalgorithm)<br>
### **SHA512**
The HMAC-SHA512 hashing algorithm.
```csharp
public static OtpAlgorithm SHA512 { get; }
```
#### Property Value
[OtpAlgorithm](simpleotp.otpalgorithm)<br>
### **MD5**
The HMAC-MD5 hashing algorithm.
```csharp
public static OtpAlgorithm MD5 { get; }
```
#### Property Value
[OtpAlgorithm](simpleotp.otpalgorithm)<br>
**Remarks:**
This is not a standard algorithm, but it is defined by IIJ specification and recognized by default.<br>Internet Initiative Japan. URI format
## Constructors
### **OtpAlgorithm(String)**
Initializes a new instance of the [OtpAlgorithm](simpleotp.otpalgorithm) struct.
```csharp
OtpAlgorithm(string value)
```
#### Parameters
`value` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The algorithm to use.
#### Exceptions
[ArgumentException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentexception)<br>
Thrown if `value` is empty or whitespace.
[ArgumentNullException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentnullexception)<br>
Thrown if `value` is .
## Methods
### **Equals(OtpAlgorithm)**
```csharp
bool Equals(OtpAlgorithm other)
```
#### Parameters
`other` [OtpAlgorithm](simpleotp.otpalgorithm)<br>
#### Returns
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
### **Equals(String)**
```csharp
bool Equals(string other)
```
#### Parameters
`other` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
#### Returns
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
### **Equals(Object)**
```csharp
bool Equals(object obj)
```
#### Parameters
`obj` [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object)<br>
#### Returns
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
### **IsStandard()**
Determines whether the specified [OtpAlgorithm](simpleotp.otpalgorithm) is standard HMAC SHA algorithm (SHA-1, SHA-256 or SHA-512).
```csharp
bool IsStandard()
```
#### Returns
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
if the specified [OtpAlgorithm](simpleotp.otpalgorithm) is standard; otherwise, .
### **GetHashCode()**
```csharp
int GetHashCode()
```
#### Returns
[Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
### **ToString()**
Returns the string representation of the [OtpAlgorithm](simpleotp.otpalgorithm) struct.
```csharp
string ToString()
```
#### Returns
[String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The string representation of the [OtpAlgorithm](simpleotp.otpalgorithm) struct.
### **GetSchema()**
```csharp
XmlSchema GetSchema()
```
#### Returns
XmlSchema<br>
### **ReadXml(XmlReader)**
```csharp
void ReadXml(XmlReader reader)
```
#### Parameters
`reader` XmlReader<br>
### **WriteXml(XmlWriter)**
```csharp
void WriteXml(XmlWriter writer)
```
#### Parameters
`writer` XmlWriter<br>
### **IsStandard(String)**
Determines whether the specified [OtpAlgorithm](simpleotp.otpalgorithm) is standard HMAC SHA algorithm (SHA-1, SHA-256 or SHA-512).
```csharp
bool IsStandard(string algorithm)
```
#### Parameters
`algorithm` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The algorithm to check.
#### Returns
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
if the specified [OtpAlgorithm](simpleotp.otpalgorithm) is standard; otherwise, .
### **IsStandard(OtpAlgorithm)**
Determines whether the specified [OtpAlgorithm](simpleotp.otpalgorithm) is standard HMAC SHA algorithm (SHA-1, SHA-256 or SHA-512).
```csharp
bool IsStandard(OtpAlgorithm algorithm)
```
#### Parameters
`algorithm` [OtpAlgorithm](simpleotp.otpalgorithm)<br>
The algorithm to check.
#### Returns
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
if the specified [OtpAlgorithm](simpleotp.otpalgorithm) is standard; otherwise, .
+299
@@ -0,0 +1,299 @@
# OtpCode
Namespace: SimpleOTP
Represents a one-time password (OTP) code.
```csharp
public struct OtpCode
```
Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [ValueType](https://docs.microsoft.com/en-us/dotnet/api/system.valuetype) → [OtpCode](simpleotp.otpcode)<br>
Implements [IEquatable&lt;OtpCode&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.iequatable-1), [IEquatable&lt;String&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.iequatable-1), IXmlSerializable<br>
Attributes [SerializableAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.serializableattribute), [NullableContextAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullablecontextattribute), [NullableAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullableattribute), [IsReadOnlyAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.isreadonlyattribute), JsonConverterAttribute
## Properties
### **CanExpire**
Gets a value indicating whether the OTP code can expire (`true` for TOTP, `false` for HOTP).
```csharp
public bool CanExpire { get; }
```
#### Property Value
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
### **ExpirationTime**
Gets the expiration time of the OTP code (TOTP only).
```csharp
public Nullable<DateTimeOffset> ExpirationTime { get; }
```
#### Property Value
[Nullable&lt;DateTimeOffset&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.nullable-1)<br>
## Constructors
### **OtpCode(Int32, Int32)**
Initializes a new instance of the [OtpCode](simpleotp.otpcode) struct with the specified value with no expiration time.
```csharp
OtpCode(int code, int digits)
```
#### Parameters
`code` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
The value of the OTP code.
`digits` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
The number of digits in the OTP code.
#### Exceptions
[ArgumentNullException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentnullexception)<br>
`code` is .
[ArgumentException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentexception)<br>
`code` is not a valid numeric code.
### **OtpCode(Int32, Int32, Nullable&lt;DateTimeOffset&gt;)**
Initializes a new instance of the [OtpCode](simpleotp.otpcode) struct with the specified value and the expiration time.
```csharp
OtpCode(int code, int digits, Nullable<DateTimeOffset> expirationTime)
```
#### Parameters
`code` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
The value of the OTP code.
`digits` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
The number of digits in the OTP code.
`expirationTime` [Nullable&lt;DateTimeOffset&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.nullable-1)<br>
The expiration time of the OTP code (TOTP only).
#### Exceptions
[ArgumentNullException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentnullexception)<br>
`code` is .
[ArgumentException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentexception)<br>
`code` is not a valid numeric code.
### **OtpCode(String)**
Initializes a new instance of the [OtpCode](simpleotp.otpcode) struct with the specified value with no expiration time.
```csharp
OtpCode(string code)
```
#### Parameters
`code` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The value of the OTP code.
#### Exceptions
[ArgumentNullException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentnullexception)<br>
`code` is .
[ArgumentException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentexception)<br>
`code` is not a valid numeric code.
### **OtpCode(String, Nullable&lt;DateTimeOffset&gt;)**
Initializes a new instance of the [OtpCode](simpleotp.otpcode) struct with the specified value and the expiration time.
```csharp
OtpCode(string code, Nullable<DateTimeOffset> expirationTime)
```
#### Parameters
`code` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The value of the OTP code.
`expirationTime` [Nullable&lt;DateTimeOffset&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.nullable-1)<br>
The expiration time of the OTP code (TOTP only).
#### Exceptions
[ArgumentNullException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentnullexception)<br>
`code` is .
[ArgumentException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentexception)<br>
`code` is not a valid numeric code.
## Methods
### **ToString()**
Returns a string representation of the OTP code.
```csharp
string ToString()
```
#### Returns
[String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
A string representation of the OTP code.
### **ToString(String)**
Returns a string representation of the OTP code.
```csharp
string ToString(string format)
```
#### Parameters
`format` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The format to use.
#### Returns
[String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The string representation of the OTP code.
### **Equals(OtpCode)**
```csharp
bool Equals(OtpCode other)
```
#### Parameters
`other` [OtpCode](simpleotp.otpcode)<br>
#### Returns
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
### **Equals(Object)**
```csharp
bool Equals(object obj)
```
#### Parameters
`obj` [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object)<br>
#### Returns
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
### **Equals(String)**
```csharp
bool Equals(string other)
```
#### Parameters
`other` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
#### Returns
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
### **GetHashCode()**
```csharp
int GetHashCode()
```
#### Returns
[Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
### **GetSchema()**
```csharp
XmlSchema GetSchema()
```
#### Returns
XmlSchema<br>
### **ReadXml(XmlReader)**
```csharp
void ReadXml(XmlReader reader)
```
#### Parameters
`reader` XmlReader<br>
### **WriteXml(XmlWriter)**
```csharp
void WriteXml(XmlWriter writer)
```
#### Parameters
`writer` XmlWriter<br>
### **Parse(String)**
Parses the specified [String](https://docs.microsoft.com/en-us/dotnet/api/system.string) into an [OtpCode](simpleotp.otpcode) object.
```csharp
OtpCode Parse(string code)
```
#### Parameters
`code` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The string to parse.
#### Returns
[OtpCode](simpleotp.otpcode)<br>
An [OtpCode](simpleotp.otpcode) object.
#### Exceptions
[ArgumentNullException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentnullexception)<br>
`code` is .
[ArgumentException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentexception)<br>
`code` is not a valid numeric code.
### **TryParse(String, OtpCode&)**
Tries to parse the specified [String](https://docs.microsoft.com/en-us/dotnet/api/system.string) into an [OtpCode](simpleotp.otpcode) object.
```csharp
bool TryParse(string code, OtpCode& result)
```
#### Parameters
`code` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The string to parse.
`result` [OtpCode&](simpleotp.otpcode&)<br>
The parsed [OtpCode](simpleotp.otpcode) object.
#### Returns
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
if `code` was parsed successfully; otherwise, .
+614
@@ -0,0 +1,614 @@
# OtpConfig
Namespace: SimpleOTP
Represents the configuration for a One-Time Password (OTP).
```csharp
public class OtpConfig : System.Xml.Serialization.IXmlSerializable, System.IEquatable`1[[SimpleOTP.OtpConfig, SimpleOTP, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]]
```
Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [OtpConfig](simpleotp.otpconfig)<br>
Implements IXmlSerializable, [IEquatable&lt;OtpConfig&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.iequatable-1)<br>
Attributes [SerializableAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.serializableattribute), [NullableContextAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullablecontextattribute), [NullableAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullableattribute), JsonConverterAttribute
## Properties
### **EqualityContract**
```csharp
protected Type EqualityContract { get; }
```
#### Property Value
[Type](https://docs.microsoft.com/en-us/dotnet/api/system.type)<br>
### **Type**
Gets or sets the type of the OTP.
```csharp
public OtpType Type { get; set; }
```
#### Property Value
[OtpType](simpleotp.otptype)<br>
Default is: [OtpType.Totp](simpleotp.otptype#totp)
**Remarks:**
Internet-Draft.<br>IMPORTANT: Some authenticators do not support [OtpType.Hotp](simpleotp.otptype#hotp).
### **IssuerLabel**
Gets or sets the issuer label prefix of the OTP.
```csharp
public string IssuerLabel { get; set; }
```
#### Property Value
[String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
**Remarks:**
-
-
-
Internet-Draft.
### **Label**
Gets or sets the label of the OTP.
```csharp
public string Label { get; set; }
```
#### Property Value
[String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
**Remarks:**
Internet-Draft.
### **Secret**
Gets or sets the secret of the OTP.
```csharp
public OtpSecret Secret { get; set; }
```
#### Property Value
[OtpSecret](simpleotp.otpsecret)<br>
Default: 160-bit key. Minimal recommended: 128 bits
**Remarks:**
Internet-Draft
### **Algorithm**
Gets or sets the hashing algorithm of the OTP.
```csharp
public OtpAlgorithm Algorithm { get; set; }
```
#### Property Value
[OtpAlgorithm](simpleotp.otpalgorithm)<br>
Default: [OtpAlgorithm.SHA1](simpleotp.otpalgorithm#sha1)
**Remarks:**
Internet-Draft<br>IMPORTANT: Some authenticators do not support algorithms other than [OtpAlgorithm.SHA1](simpleotp.otpalgorithm#sha1).
### **Issuer**
Gets or sets the issuer of the OTP. Optional.
```csharp
public string Issuer { get; set; }
```
#### Property Value
[String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
**Remarks:**
-
-
Internet-Draft
### **Digits**
Gets or sets the number of digits of the OTP codes.
```csharp
public int Digits { get; set; }
```
#### Property Value
[Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
Default: 6. Recommended: 6 or 8
**Remarks:**
Internet-Draft<br>IMPORTANT: Some authenticators do not support digits other than 6.
### **Counter**
Gets or sets the counter of the OTP. Required for [OtpType.Hotp](simpleotp.otptype#hotp). Ignored for [OtpType.Totp](simpleotp.otptype#totp).
```csharp
public long Counter { get; set; }
```
#### Property Value
[Int64](https://docs.microsoft.com/en-us/dotnet/api/system.int64)<br>
Default: 0
**Remarks:**
Internet-Draft<br>IMPORTANT: Some authenticators do not support [OtpType.Hotp](simpleotp.otptype#hotp).
### **Period**
Gets or sets the period of the OTP in seconds. Optional for [OtpType.Totp](simpleotp.otptype#totp). Ignored for [OtpType.Hotp](simpleotp.otptype#hotp).
```csharp
public int Period { get; set; }
```
#### Property Value
[Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
Default: 30
**Remarks:**
Internet-Draft<br>IMPORTANT: Some authenticators support only periods of 30 seconds.
### **CustomProperties**
Gets the custom vendor-specified properties of the current OTP configuration.
```csharp
public NameValueCollection CustomProperties { get; }
```
#### Property Value
NameValueCollection<br>
**Remarks:**
If set, reserved keys
`issuer, digits, counter, secret, period and algorithm`
will be removed from the [OtpConfig.CustomProperties](simpleotp.otpconfig#customproperties) upon it's serialization to URI.<br>Internet-Draft
## Constructors
### **OtpConfig(String)**
Initializes a new instance of the [OtpConfig](simpleotp.otpconfig) class.
```csharp
public OtpConfig(string label)
```
#### Parameters
`label` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The label of the OTP config.
### **OtpConfig(String, String)**
Initializes a new instance of the [OtpConfig](simpleotp.otpconfig) class.
```csharp
public OtpConfig(string label, string issuer)
```
#### Parameters
`label` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The label of the OTP config.
`issuer` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The issuer of the OTP config.
### **OtpConfig(String, OtpSecret)**
Initializes a new instance of the [OtpConfig](simpleotp.otpconfig) class.
```csharp
public OtpConfig(string label, OtpSecret secret)
```
#### Parameters
`label` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The label of the OTP config.
`secret` [OtpSecret](simpleotp.otpsecret)<br>
The secret of the OTP config.
### **OtpConfig(String, String, OtpSecret)**
Initializes a new instance of the [OtpConfig](simpleotp.otpconfig) class.
```csharp
public OtpConfig(string label, string issuer, OtpSecret secret)
```
#### Parameters
`label` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The label of the OTP config.
`issuer` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The issuer of the OTP config.
`secret` [OtpSecret](simpleotp.otpsecret)<br>
The secret of the OTP config.
### **OtpConfig(Uri)**
Initializes a new instance of the [OtpConfig](simpleotp.otpconfig) class.
```csharp
public OtpConfig(Uri uri)
```
#### Parameters
`uri` Uri<br>
The URI of the OTP config.
#### Exceptions
[ArgumentException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentexception)<br>
Provided URI is not valid (missing required values or has invalid required values).
### **OtpConfig(Uri, IEncoder)**
Initializes a new instance of the [OtpConfig](simpleotp.otpconfig) class.
```csharp
public OtpConfig(Uri uri, IEncoder encoder)
```
#### Parameters
`uri` Uri<br>
The URI of the OTP config.
`encoder` [IEncoder](simpleotp.encoding.iencoder)<br>
The encoder used to decode the secret.
#### Exceptions
[ArgumentException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentexception)<br>
Provided URI is not valid (missing required values or has invalid required values).
### **OtpConfig(OtpConfig)**
```csharp
protected OtpConfig(OtpConfig original)
```
#### Parameters
`original` [OtpConfig](simpleotp.otpconfig)<br>
## Methods
### **ToUri()**
Converts the current [OtpConfig](simpleotp.otpconfig) object to a object.
```csharp
public Uri ToUri()
```
#### Returns
Uri<br>
A object representing the current [OtpConfig](simpleotp.otpconfig) object.
**Remarks:**
Uses minimal Google specified formatting ([OtpUriFormat.Minimal](simpleotp.otpuriformat#minimal) | [OtpUriFormat.Google](simpleotp.otpuriformat#google)).
### **ToUri(OtpUriFormat)**
Converts the current [OtpConfig](simpleotp.otpconfig) object to a object.
```csharp
public Uri ToUri(OtpUriFormat format)
```
#### Parameters
`format` [OtpUriFormat](simpleotp.otpuriformat)<br>
A bitwise combination of the enumeration values that specifies the format of the URI.
#### Returns
Uri<br>
A object representing the current [OtpConfig](simpleotp.otpconfig) object.
### **IsValid(String&, OtpUriFormat)**
Returns if the specified [OtpConfig](simpleotp.otpconfig) object is valid.
```csharp
public void IsValid(String& error, OtpUriFormat format)
```
#### Parameters
`error` [String&](https://docs.microsoft.com/en-us/dotnet/api/system.string&)<br>
The error message returned if the [OtpConfig](simpleotp.otpconfig) object is invalid.
`format` [OtpUriFormat](simpleotp.otpuriformat)<br>
The [OtpUriFormat](simpleotp.otpuriformat) to use for validation.
### **ToString()**
```csharp
public string ToString()
```
#### Returns
[String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
### **GetSchema()**
```csharp
public XmlSchema GetSchema()
```
#### Returns
XmlSchema<br>
### **ReadXml(XmlReader)**
```csharp
public void ReadXml(XmlReader reader)
```
#### Parameters
`reader` XmlReader<br>
### **WriteXml(XmlWriter)**
```csharp
public void WriteXml(XmlWriter writer)
```
#### Parameters
`writer` XmlWriter<br>
### **ParseUri(Uri)**
Parses the specified URI into an [OtpConfig](simpleotp.otpconfig) object.
```csharp
public static OtpConfig ParseUri(Uri uri)
```
#### Parameters
`uri` Uri<br>
The URI to parse.
#### Returns
[OtpConfig](simpleotp.otpconfig)<br>
An [OtpConfig](simpleotp.otpconfig) object parsed from the specified URI.
#### Exceptions
[ArgumentException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentexception)<br>
Provided URI is not valid (missing required values or has invalid required values).
### **ParseUri(Uri, IEncoder)**
Initializes a new instance of the [OtpConfig](simpleotp.otpconfig) class.
```csharp
public static OtpConfig ParseUri(Uri uri, IEncoder encoder)
```
#### Parameters
`uri` Uri<br>
The URI of the OTP.
`encoder` [IEncoder](simpleotp.encoding.iencoder)<br>
The encoder used to decode the secret.
#### Returns
[OtpConfig](simpleotp.otpconfig)<br>
#### Exceptions
[ArgumentException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentexception)<br>
Provided URI is not valid (missing required values or has invalid required values).
### **ParseUri(String)**
Parses the specified URI into an [OtpConfig](simpleotp.otpconfig) object.
```csharp
public static OtpConfig ParseUri(string uri)
```
#### Parameters
`uri` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The URI to parse.
#### Returns
[OtpConfig](simpleotp.otpconfig)<br>
An [OtpConfig](simpleotp.otpconfig) object parsed from the specified URI.
#### Exceptions
[ArgumentException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentexception)<br>
Provided URI is not valid (missing required values or has invalid required values).
T:System.UriFormatException<br>
Provided URI is not valid (missing required values or has invalid required values).
### **TryParseUri(Uri, OtpConfig&)**
Tries to parse the specified URI into an [OtpConfig](simpleotp.otpconfig) object.
```csharp
public static bool TryParseUri(Uri uri, OtpConfig& config)
```
#### Parameters
`uri` Uri<br>
The URI to parse.
`config` [OtpConfig&](simpleotp.otpconfig&)<br>
When this method returns, contains the [OtpConfig](simpleotp.otpconfig) object parsed from the specified URI, if the conversion succeeded, or `null` if the conversion failed.
#### Returns
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
`true` if the conversion succeeded; otherwise, `false`.
### **TryParseUri(String, OtpConfig&)**
Tries to parse the specified URI into an [OtpConfig](simpleotp.otpconfig) object.
```csharp
public static bool TryParseUri(string uri, OtpConfig& config)
```
#### Parameters
`uri` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The URI to parse.
`config` [OtpConfig&](simpleotp.otpconfig&)<br>
When this method returns, contains the [OtpConfig](simpleotp.otpconfig) object parsed from the specified URI, if the conversion succeeded, or `null` if the conversion failed.
#### Returns
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
`true` if the conversion succeeded; otherwise, `false`.
### **Validate(OtpConfig, String&, OtpUriFormat)**
Returns if the specified [OtpConfig](simpleotp.otpconfig) object is valid.
```csharp
public static bool Validate(OtpConfig config, String& error, OtpUriFormat format)
```
#### Parameters
`config` [OtpConfig](simpleotp.otpconfig)<br>
The [OtpConfig](simpleotp.otpconfig) object to validate.
`error` [String&](https://docs.microsoft.com/en-us/dotnet/api/system.string&)<br>
The error message returned if the [OtpConfig](simpleotp.otpconfig) object is invalid.
`format` [OtpUriFormat](simpleotp.otpuriformat)<br>
The [OtpUriFormat](simpleotp.otpuriformat) to use for validation.
#### Returns
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
`true` if the conversion succeeded; otherwise, `false`.
**Remarks:**
The `format` should contain at least one vendor-specific format.
### **PrintMembers(StringBuilder)**
```csharp
protected bool PrintMembers(StringBuilder builder)
```
#### Parameters
`builder` [StringBuilder](https://docs.microsoft.com/en-us/dotnet/api/system.text.stringbuilder)<br>
#### Returns
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
### **GetHashCode()**
```csharp
public int GetHashCode()
```
#### Returns
[Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
### **Equals(Object)**
```csharp
public bool Equals(object obj)
```
#### Parameters
`obj` [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object)<br>
#### Returns
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
### **Equals(OtpConfig)**
```csharp
public bool Equals(OtpConfig other)
```
#### Parameters
`other` [OtpConfig](simpleotp.otpconfig)<br>
#### Returns
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
### **&lt;Clone&gt;$()**
```csharp
public OtpConfig <Clone>$()
```
#### Returns
[OtpConfig](simpleotp.otpconfig)<br>
+434
@@ -0,0 +1,434 @@
# OtpSecret
Namespace: SimpleOTP
Represents a one-time password secret.
```csharp
public class OtpSecret : System.IEquatable`1[[SimpleOTP.OtpSecret, SimpleOTP, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]], System.IEquatable`1[[System.Byte[], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Xml.Serialization.IXmlSerializable, System.IDisposable
```
Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [OtpSecret](simpleotp.otpsecret)<br>
Implements [IEquatable&lt;OtpSecret&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.iequatable-1), [IEquatable&lt;Byte[]&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.iequatable-1), IXmlSerializable, [IDisposable](https://docs.microsoft.com/en-us/dotnet/api/system.idisposable)<br>
Attributes [SerializableAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.serializableattribute), [NullableContextAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullablecontextattribute), [NullableAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullableattribute), JsonConverterAttribute
## Properties
### **DefaultEncoder**
Gets or sets the default encoder for parsing/encoding/serializing secrets.
```csharp
public static IEncoder DefaultEncoder { get; set; }
```
#### Property Value
[IEncoder](simpleotp.encoding.iencoder)<br>
## Constructors
### **OtpSecret()**
Initializes a new instance of the [OtpSecret](simpleotp.otpsecret) class with a default length of 20 bytes (160 bits).
```csharp
public OtpSecret()
```
### **OtpSecret(Int32)**
Initializes a new instance of the [OtpSecret](simpleotp.otpsecret) class with a random secret of the specified length.
```csharp
public OtpSecret(int length)
```
#### Parameters
`length` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
The length of the secret in bytes.
#### Exceptions
[ArgumentOutOfRangeException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentoutofrangeexception)<br>
`length` is less than 1.
**Remarks:**
20 bytes (160 bits) is the recommended key length specified by RFC 4226.
Minimal recommended length is 16 bytes (128 bits).
### **OtpSecret(Byte[])**
Initializes a new instance of the [OtpSecret](simpleotp.otpsecret) class from a byte array.
```csharp
public OtpSecret(Byte[] secret)
```
#### Parameters
`secret` [Byte[]](https://docs.microsoft.com/en-us/dotnet/api/system.byte)<br>
The byte array.
#### Exceptions
[ArgumentNullException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentnullexception)<br>
`secret` is `null` or empty.
### **OtpSecret(String)**
Initializes a new instance of the [OtpSecret](simpleotp.otpsecret) class from a Base32-encoded string (RFC 4648 §6).
```csharp
public OtpSecret(string secret)
```
#### Parameters
`secret` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The Base32-encoded string.
#### Exceptions
[ArgumentNullException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentnullexception)<br>
`secret` is `null`.
[ArgumentException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentexception)<br>
`secret` is empty or contains invalid characters or only whitespace.
### **OtpSecret(String, IEncoder)**
Initializes a new instance of the [OtpSecret](simpleotp.otpsecret) class from an encoded string.
```csharp
public OtpSecret(string secret, IEncoder encoder)
```
#### Parameters
`secret` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The encoded string.
`encoder` [IEncoder](simpleotp.encoding.iencoder)<br>
The encoder.
#### Exceptions
[ArgumentNullException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentnullexception)<br>
`secret` is `null` or empty.
[ArgumentException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentexception)<br>
`secret` is empty or contains invalid characters or only whitespace.
## Methods
### **ToString()**
Returns the Base32-encoded string representation of the current [OtpSecret](simpleotp.otpsecret) object.
```csharp
public string ToString()
```
#### Returns
[String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The Base32-encoded string representation of the current [OtpSecret](simpleotp.otpsecret) object.
### **ToString(IEncoder)**
Returns the string representation of the current [OtpSecret](simpleotp.otpsecret) object.
```csharp
public string ToString(IEncoder encoder)
```
#### Parameters
`encoder` [IEncoder](simpleotp.encoding.iencoder)<br>
The encoder.
#### Returns
[String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The string representation of the current [OtpSecret](simpleotp.otpsecret) object.
### **Equals(OtpSecret)**
```csharp
public bool Equals(OtpSecret other)
```
#### Parameters
`other` [OtpSecret](simpleotp.otpsecret)<br>
#### Returns
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
### **Equals(Object)**
```csharp
public bool Equals(object obj)
```
#### Parameters
`obj` [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object)<br>
#### Returns
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
### **Equals(Byte[])**
```csharp
public bool Equals(Byte[] other)
```
#### Parameters
`other` [Byte[]](https://docs.microsoft.com/en-us/dotnet/api/system.byte)<br>
#### Returns
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
### **GetHashCode()**
```csharp
public int GetHashCode()
```
#### Returns
[Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
### **Dispose()**
```csharp
public void Dispose()
```
### **GetSchema()**
```csharp
public XmlSchema GetSchema()
```
#### Returns
XmlSchema<br>
### **ReadXml(XmlReader)**
```csharp
public void ReadXml(XmlReader reader)
```
#### Parameters
`reader` XmlReader<br>
### **WriteXml(XmlWriter)**
```csharp
public void WriteXml(XmlWriter writer)
```
#### Parameters
`writer` XmlWriter<br>
### **CreateCopy(OtpSecret)**
Creates a copy of the specified [OtpSecret](simpleotp.otpsecret) object.
```csharp
public static OtpSecret CreateCopy(OtpSecret source)
```
#### Parameters
`source` [OtpSecret](simpleotp.otpsecret)<br>
The [OtpSecret](simpleotp.otpsecret) object to copy.
#### Returns
[OtpSecret](simpleotp.otpsecret)<br>
A copy of the specified [OtpSecret](simpleotp.otpsecret) object.
### **CreateNew()**
Creates a new random [OtpSecret](simpleotp.otpsecret) object with a default length of 20 bytes.
```csharp
public static OtpSecret CreateNew()
```
#### Returns
[OtpSecret](simpleotp.otpsecret)<br>
A new random [OtpSecret](simpleotp.otpsecret) object.
**Remarks:**
20 bytes (160 bits) is the recommended key length specified by RFC 4226.
Minimal recommended length is 16 bytes (128 bits).
### **CreateNew(Int32)**
Creates a new random [OtpSecret](simpleotp.otpsecret) object with the specified length.
```csharp
public static OtpSecret CreateNew(int length)
```
#### Parameters
`length` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
The length of the secret in bytes.
#### Returns
[OtpSecret](simpleotp.otpsecret)<br>
A new random [OtpSecret](simpleotp.otpsecret) object.
#### Exceptions
[ArgumentOutOfRangeException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentoutofrangeexception)<br>
`length` is less than 1.
**Remarks:**
20 bytes (160 bits) is the recommended key length specified by RFC 4226.
Minimal recommended length is 16 bytes (128 bits).
### **Parse(String)**
Parses a Base32-encoded string into an [OtpSecret](simpleotp.otpsecret) object.
```csharp
public static OtpSecret Parse(string secret)
```
#### Parameters
`secret` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The Base32-encoded string.
#### Returns
[OtpSecret](simpleotp.otpsecret)<br>
An [OtpSecret](simpleotp.otpsecret) object.
#### Exceptions
[ArgumentNullException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentnullexception)<br>
`secret` is `null`.
[ArgumentException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentexception)<br>
`secret` is empty or contains invalid characters or only whitespace.
### **Parse(String, IEncoder)**
Parses a Base32-encoded string into an [OtpSecret](simpleotp.otpsecret) object.
```csharp
public static OtpSecret Parse(string secret, IEncoder encoder)
```
#### Parameters
`secret` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The Base32-encoded string.
`encoder` [IEncoder](simpleotp.encoding.iencoder)<br>
The encoder.
#### Returns
[OtpSecret](simpleotp.otpsecret)<br>
An [OtpSecret](simpleotp.otpsecret) object.
#### Exceptions
[ArgumentNullException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentnullexception)<br>
`secret` is `null`.
[ArgumentException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentexception)<br>
`secret` is empty or contains invalid characters or only whitespace.
### **TryParse(String, OtpSecret&)**
Tries to parse a Base32-encoded string into an [OtpSecret](simpleotp.otpsecret) object.
```csharp
public static bool TryParse(string secret, OtpSecret& otpSecret)
```
#### Parameters
`secret` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The Base32-encoded string.
`otpSecret` [OtpSecret&](simpleotp.otpsecret&)<br>
When this method returns, contains the [OtpSecret](simpleotp.otpsecret) object, if the conversion succeeded, or `default` if the conversion failed.
#### Returns
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
`true` if `secret` was converted successfully; otherwise, `false`.
### **TryParse(String, IEncoder, OtpSecret&)**
Tries to parse a Base32-encoded string into an [OtpSecret](simpleotp.otpsecret) object.
```csharp
public static bool TryParse(string secret, IEncoder encoder, OtpSecret& otpSecret)
```
#### Parameters
`secret` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The Base32-encoded string.
`encoder` [IEncoder](simpleotp.encoding.iencoder)<br>
The encoder.
`otpSecret` [OtpSecret&](simpleotp.otpsecret&)<br>
When this method returns, contains the [OtpSecret](simpleotp.otpsecret) object, if the conversion succeeded, or `default` if the conversion failed.
#### Returns
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
`true` if `secret` was converted successfully; otherwise, `false`.
### **FromBytes(Byte[])**
Creates a new [OtpSecret](simpleotp.otpsecret) object from a byte array.
```csharp
public static OtpSecret FromBytes(Byte[] secret)
```
#### Parameters
`secret` [Byte[]](https://docs.microsoft.com/en-us/dotnet/api/system.byte)<br>
The byte array.
#### Returns
[OtpSecret](simpleotp.otpsecret)<br>
An [OtpSecret](simpleotp.otpsecret) object.
#### Exceptions
[ArgumentNullException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentnullexception)<br>
`secret` is `null`.
[ArgumentOutOfRangeException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentoutofrangeexception)<br>
`secret` is empty.
+19
@@ -0,0 +1,19 @@
# OtpType
Namespace: SimpleOTP
Represents the type of One-Time Password (OTP).
```csharp
public enum OtpType
```
Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [ValueType](https://docs.microsoft.com/en-us/dotnet/api/system.valuetype) → [Enum](https://docs.microsoft.com/en-us/dotnet/api/system.enum) → [OtpType](simpleotp.otptype)<br>
Implements [IComparable](https://docs.microsoft.com/en-us/dotnet/api/system.icomparable), [ISpanFormattable](https://docs.microsoft.com/en-us/dotnet/api/system.ispanformattable), [IFormattable](https://docs.microsoft.com/en-us/dotnet/api/system.iformattable), [IConvertible](https://docs.microsoft.com/en-us/dotnet/api/system.iconvertible)
## Fields
| Name | Value | Description |
| --- | --: | --- |
| Totp | 0 | Time-based One-Time Password (TOTP). |
| Hotp | 1 | HMAC-based One-Time Password (HOTP). |
+24
@@ -0,0 +1,24 @@
# OtpUriFormat
Namespace: SimpleOTP
Bitwise flags for specifying the format of One-Time Password (OTP) URIs.
```csharp
public enum OtpUriFormat
```
Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [ValueType](https://docs.microsoft.com/en-us/dotnet/api/system.valuetype) → [Enum](https://docs.microsoft.com/en-us/dotnet/api/system.enum) → [OtpUriFormat](simpleotp.otpuriformat)<br>
Implements [IComparable](https://docs.microsoft.com/en-us/dotnet/api/system.icomparable), [ISpanFormattable](https://docs.microsoft.com/en-us/dotnet/api/system.ispanformattable), [IFormattable](https://docs.microsoft.com/en-us/dotnet/api/system.iformattable), [IConvertible](https://docs.microsoft.com/en-us/dotnet/api/system.iconvertible)
## Fields
| Name | Value | Description |
| --- | --: | --- |
| Minimal | 1 | Represents a minimal URI format - only non-default properties are included. |
| Full | 2 | Represents a full URI format - all properties are included. |
| Google | 16 | Represents a Google URI format. |
| Apple | 32 | Represents an Apple URI format. |
| IBM | 64 | Represents an IBM URI format. |
| Yubico | 128 | Represents a Yubico URI format. |
| IIJ | 256 | Represents an IIJ URI format. |
+137
@@ -0,0 +1,137 @@
# ToleranceSpan
Namespace: SimpleOTP
Represents a span of tolerance values used in OTP (One-Time Password) validation.
```csharp
public struct ToleranceSpan
```
Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [ValueType](https://docs.microsoft.com/en-us/dotnet/api/system.valuetype) → [ToleranceSpan](simpleotp.tolerancespan)<br>
Implements [IEquatable&lt;ToleranceSpan&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.iequatable-1)<br>
Attributes [IsReadOnlyAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.isreadonlyattribute)
## Properties
### **Default**
Gets the default recommended [ToleranceSpan](simpleotp.tolerancespan) value.
```csharp
public static ToleranceSpan Default { get; }
```
#### Property Value
[ToleranceSpan](simpleotp.tolerancespan)<br>
The default [ToleranceSpan](simpleotp.tolerancespan) value: 1 counter/period ahead and behind.
### **Behind**
Gets the number of tolerance values behind the current value.
```csharp
public int Behind { get; set; }
```
#### Property Value
[Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
### **Ahead**
Gets the number of tolerance values ahead of the current value.
```csharp
public int Ahead { get; set; }
```
#### Property Value
[Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
## Constructors
### **ToleranceSpan(Int32, Int32)**
Represents a span of tolerance values used in OTP (One-Time Password) validation.
```csharp
ToleranceSpan(int behind, int ahead)
```
#### Parameters
`behind` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
The number of periods/counter values behind the current value.
`ahead` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
The number of periods/counter values ahead of the current value.
### **ToleranceSpan(Int32)**
Initializes a new instance of the [ToleranceSpan](simpleotp.tolerancespan) struct with the specified tolerance value.
The [ToleranceSpan.Behind](simpleotp.tolerancespan#behind) and [ToleranceSpan.Ahead](simpleotp.tolerancespan#ahead) properties will be set to the same value.
```csharp
ToleranceSpan(int tolerance)
```
#### Parameters
`tolerance` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
The tolerance value to set for both [ToleranceSpan.Behind](simpleotp.tolerancespan#behind) and [ToleranceSpan.Ahead](simpleotp.tolerancespan#ahead).
## Methods
### **Equals(ToleranceSpan)**
```csharp
bool Equals(ToleranceSpan other)
```
#### Parameters
`other` [ToleranceSpan](simpleotp.tolerancespan)<br>
#### Returns
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
### **Equals(Object)**
```csharp
bool Equals(object obj)
```
#### Parameters
`obj` [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object)<br>
#### Returns
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
### **GetHashCode()**
```csharp
int GetHashCode()
```
#### Returns
[Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
### **ToString()**
Returns the string representation of the [ToleranceSpan](simpleotp.tolerancespan) struct.
```csharp
string ToString()
```
#### Returns
[String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The string representation of the [ToleranceSpan](simpleotp.tolerancespan) struct.
+209
@@ -0,0 +1,209 @@
# Totp
Namespace: SimpleOTP
Represents a Time-based One-Time Password (TOTP) generator.
```csharp
public class Totp : Otp
```
Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [Otp](simpleotp.otp) → [Totp](simpleotp.totp)<br>
Attributes [NullableContextAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullablecontextattribute), [NullableAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullableattribute)
## Properties
### **Period**
Gets or sets the time period (in seconds) for which each generated OTP is valid.
```csharp
public int Period { get; set; }
```
#### Property Value
[Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
**Remarks:**
Also used to calculate the current counter value.
### **Secret**
Gets or sets the secret key used for generating OTPs.
```csharp
public OtpSecret Secret { get; set; }
```
#### Property Value
[OtpSecret](simpleotp.otpsecret)<br>
### **Algorithm**
Gets or sets the algorithm used for generating OTP codes.
```csharp
public OtpAlgorithm Algorithm { get; set; }
```
#### Property Value
[OtpAlgorithm](simpleotp.otpalgorithm)<br>
### **Digits**
Gets or sets the number of digits in the OTP code.
```csharp
public int Digits { get; set; }
```
#### Property Value
[Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
Default: 6. Recommended: 6-8.
## Constructors
### **Totp(OtpSecret)**
Initializes a new instance of the [Totp](simpleotp.totp) class with the specified secret key.
```csharp
public Totp(OtpSecret secret)
```
#### Parameters
`secret` [OtpSecret](simpleotp.otpsecret)<br>
The secret key used for generating OTP codes.
### **Totp(OtpSecret, Int32)**
Initializes a new instance of the [Totp](simpleotp.totp) class with the specified secret key and number of OTP code digits.
```csharp
public Totp(OtpSecret secret, int period)
```
#### Parameters
`secret` [OtpSecret](simpleotp.otpsecret)<br>
The secret key used for generating OTP codes.
`period` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
The time period (in seconds) for which each generated OTP is valid.
### **Totp(OtpSecret, Int32, Int32)**
Initializes a new instance of the [Totp](simpleotp.totp) class with the specified secret key, number of OTP code digits, and time period.
```csharp
public Totp(OtpSecret secret, int period, int digits)
```
#### Parameters
`secret` [OtpSecret](simpleotp.otpsecret)<br>
The secret key used for generating OTP codes.
`period` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
The time period (in seconds) for which each generated OTP is valid.
`digits` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
The number of digits in the OTP code.
### **Totp(OtpSecret, Int32, OtpAlgorithm)**
Initializes a new instance of the [Totp](simpleotp.totp) class with the specified secret key, hash algorithm, and time period.
```csharp
public Totp(OtpSecret secret, int period, OtpAlgorithm algorithm)
```
#### Parameters
`secret` [OtpSecret](simpleotp.otpsecret)<br>
The secret key used for generating OTP codes.
`period` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
The time period (in seconds) for which each generated OTP is valid.
`algorithm` [OtpAlgorithm](simpleotp.otpalgorithm)<br>
The algorithm used for generating OTP codes.
### **Totp(OtpSecret, Int32, OtpAlgorithm, Int32)**
Initializes a new instance of the [Totp](simpleotp.totp) class with the specified secret key, hash algorithm, number of digits, and time period.
```csharp
public Totp(OtpSecret secret, int period, OtpAlgorithm algorithm, int digits)
```
#### Parameters
`secret` [OtpSecret](simpleotp.otpsecret)<br>
The secret key used for generating OTP codes.
`period` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
The time period (in seconds) for which each generated OTP is valid.
`algorithm` [OtpAlgorithm](simpleotp.otpalgorithm)<br>
The algorithm used for generating OTP codes.
`digits` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
The number of digits in the OTP code.
## Methods
### **Generate(Int64)**
Generates an OTP based on the specified counter value.
```csharp
public OtpCode Generate(long counter)
```
#### Parameters
`counter` [Int64](https://docs.microsoft.com/en-us/dotnet/api/system.int64)<br>
The counter value to use for OTP generation.
#### Returns
[OtpCode](simpleotp.otpcode)<br>
An instance of [OtpCode](simpleotp.otpcode) representing the generated OTP.
### **Generate(DateTimeOffset)**
Generates an OTP based on the specified date and time.
```csharp
public OtpCode Generate(DateTimeOffset date)
```
#### Parameters
`date` [DateTimeOffset](https://docs.microsoft.com/en-us/dotnet/api/system.datetimeoffset)<br>
The date and time to use for OTP generation.
#### Returns
[OtpCode](simpleotp.otpcode)<br>
An instance of [OtpCode](simpleotp.otpcode) representing the generated OTP.
### **GetCounter()**
Gets the current counter value based on the current UTC time and the configured time period.
```csharp
protected long GetCounter()
```
#### Returns
[Int64](https://docs.microsoft.com/en-us/dotnet/api/system.int64)<br>
The current counter value.