-
-
Notifications
You must be signed in to change notification settings - Fork 1
simpleotp.otpconfig
Namespace: SimpleOTP
Represents the configuration for a One-Time Password (OTP).
public class OtpConfig : System.Xml.Serialization.IXmlSerializable, System.IEquatable`1[[SimpleOTP.OtpConfig, SimpleOTP, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]]
Inheritance Object → OtpConfig
Implements IXmlSerializable, IEquatable<OtpConfig>
Attributes SerializableAttribute, NullableContextAttribute, NullableAttribute, JsonConverterAttribute
protected Type EqualityContract { get; }
Gets or sets the type of the OTP.
public OtpType Type { get; set; }
OtpType
Default is: OtpType.Totp
Remarks:
Internet-Draft.
IMPORTANT: Some authenticators do not support OtpType.Hotp.
Gets or sets the issuer label prefix of the OTP.
public string IssuerLabel { get; set; }
Remarks:
Internet-Draft.
Gets or sets the label of the OTP.
public string Label { get; set; }
Remarks:
Internet-Draft.
Gets or sets the secret of the OTP.
public OtpSecret Secret { get; set; }
OtpSecret
Default: 160-bit key. Minimal recommended: 128 bits
Remarks:
Internet-Draft
Gets or sets the hashing algorithm of the OTP.
public OtpAlgorithm Algorithm { get; set; }
OtpAlgorithm
Default: OtpAlgorithm.SHA1
Remarks:
Internet-Draft
IMPORTANT: Some authenticators do not support algorithms other than OtpAlgorithm.SHA1.
Gets or sets the issuer of the OTP. Optional.
public string Issuer { get; set; }
Remarks:
Internet-Draft
Gets or sets the number of digits of the OTP codes.
public int Digits { get; set; }
Int32
Default: 6. Recommended: 6 or 8
Remarks:
Internet-Draft
IMPORTANT: Some authenticators do not support digits other than 6.
Gets or sets the counter of the OTP. Required for OtpType.Hotp. Ignored for OtpType.Totp.
public long Counter { get; set; }
Int64
Default: 0
Remarks:
Internet-Draft
IMPORTANT: Some authenticators do not support OtpType.Hotp.
Gets or sets the period of the OTP in seconds. Optional for OtpType.Totp. Ignored for OtpType.Hotp.
public int Period { get; set; }
Int32
Default: 30
Remarks:
Internet-Draft
IMPORTANT: Some authenticators support only periods of 30 seconds.
Gets the custom vendor-specified properties of the current OTP configuration.
public NameValueCollection CustomProperties { get; }
NameValueCollection
Remarks:
If set, reserved keys
issuer, digits, counter, secret, period and algorithm
will be removed from the OtpConfig.CustomProperties upon it's serialization to URI.
Internet-Draft
Initializes a new instance of the OtpConfig class.
public OtpConfig(string label)
label
String
The label of the OTP config.
Initializes a new instance of the OtpConfig class.
public OtpConfig(string label, string issuer)
label
String
The label of the OTP config.
issuer
String
The issuer of the OTP config.
Initializes a new instance of the OtpConfig class.
public OtpConfig(string label, OtpSecret secret)
label
String
The label of the OTP config.
secret
OtpSecret
The secret of the OTP config.
Initializes a new instance of the OtpConfig class.
public OtpConfig(string label, string issuer, OtpSecret secret)
label
String
The label of the OTP config.
issuer
String
The issuer of the OTP config.
secret
OtpSecret
The secret of the OTP config.
Initializes a new instance of the OtpConfig class.
public OtpConfig(Uri uri)
uri
Uri
The URI of the OTP config.
ArgumentException
Provided URI is not valid (missing required values or has invalid required values).
Initializes a new instance of the OtpConfig class.
public OtpConfig(Uri uri, IEncoder encoder)
uri
Uri
The URI of the OTP config.
encoder
IEncoder
The encoder used to decode the secret.
ArgumentException
Provided URI is not valid (missing required values or has invalid required values).
protected OtpConfig(OtpConfig original)
original
OtpConfig
Converts the current OtpConfig object to a object.
public Uri ToUri()
Uri
A object representing the current OtpConfig object.
Remarks:
Uses minimal Google specified formatting (OtpUriFormat.Minimal | OtpUriFormat.Google).
Converts the current OtpConfig object to a object.
public Uri ToUri(OtpUriFormat format)
format
OtpUriFormat
A bitwise combination of the enumeration values that specifies the format of the URI.
Uri
A object representing the current OtpConfig object.
Returns if the specified OtpConfig object is valid.
public void IsValid(String& error, OtpUriFormat format)
error
String&
The error message returned if the OtpConfig object is invalid.
format
OtpUriFormat
The OtpUriFormat to use for validation.
public string ToString()
public XmlSchema GetSchema()
XmlSchema
public void ReadXml(XmlReader reader)
reader
XmlReader
public void WriteXml(XmlWriter writer)
writer
XmlWriter
Parses the specified URI into an OtpConfig object.
public static OtpConfig ParseUri(Uri uri)
uri
Uri
The URI to parse.
OtpConfig
An OtpConfig object parsed from the specified URI.
ArgumentException
Provided URI is not valid (missing required values or has invalid required values).
Initializes a new instance of the OtpConfig class.
public static OtpConfig ParseUri(Uri uri, IEncoder encoder)
uri
Uri
The URI of the OTP.
encoder
IEncoder
The encoder used to decode the secret.
ArgumentException
Provided URI is not valid (missing required values or has invalid required values).
Parses the specified URI into an OtpConfig object.
public static OtpConfig ParseUri(string uri)
uri
String
The URI to parse.
OtpConfig
An OtpConfig object parsed from the specified URI.
ArgumentException
Provided URI is not valid (missing required values or has invalid required values).
T:System.UriFormatException
Provided URI is not valid (missing required values or has invalid required values).
Tries to parse the specified URI into an OtpConfig object.
public static bool TryParseUri(Uri uri, OtpConfig& config)
uri
Uri
The URI to parse.
config
OtpConfig&
When this method returns, contains the OtpConfig object parsed from the specified URI, if the conversion succeeded, or null
if the conversion failed.
Boolean
true
if the conversion succeeded; otherwise, false
.
Tries to parse the specified URI into an OtpConfig object.
public static bool TryParseUri(string uri, OtpConfig& config)
uri
String
The URI to parse.
config
OtpConfig&
When this method returns, contains the OtpConfig object parsed from the specified URI, if the conversion succeeded, or null
if the conversion failed.
Boolean
true
if the conversion succeeded; otherwise, false
.
Returns if the specified OtpConfig object is valid.
public static bool Validate(OtpConfig config, String& error, OtpUriFormat format)
config
OtpConfig
The OtpConfig object to validate.
error
String&
The error message returned if the OtpConfig object is invalid.
format
OtpUriFormat
The OtpUriFormat to use for validation.
Boolean
true
if the conversion succeeded; otherwise, false
.
Remarks:
The format
should contain at least one vendor-specific format.
protected bool PrintMembers(StringBuilder builder)
builder
StringBuilder
public int GetHashCode()
public bool Equals(object obj)
obj
Object
public bool Equals(OtpConfig other)
other
OtpConfig
public OtpConfig <Clone>$()
©2025 Eugene Fox. Licensed under MIT license