MultiCharCheckDigitAlgorithm Class
Definition
Represents the abstract base class from which check-digit algorithms that emit a fixed-length multi-character check code - most notably ISO 7064 MOD 97-10 and its derivatives (IBAN, LEI) - derive.
public abstract class MultiCharCheckDigitAlgorithm : CheckValueAlgorithm
- Inheritance
-
MultiCharCheckDigitAlgorithm
- Derived
- Inherited Members
- Extension Methods
Examples
// Use a concrete derivative through the abstract surface - IBAN emits a two-digit check.
MultiCharCheckDigitAlgorithm algo = new Iban();
algo.Append("GBWEST12345698765432"); // country code + BBAN
Span<char> check = stackalloc char[algo.CheckLength];
algo.GetCurrentCheckDigits(check); // "82"
Remarks
Parallel in design to CheckDigitAlgorithm, this base generalizes the output from a single character to a run of CheckLength decimal digits, and broadens the input to whichever subset of ASCII the concrete algorithm accepts via InputAlphabet.
Like the rest of this family, the type is intentionally separate from the byte-stream oriented NonCryptographicHashAlgorithm and does not derive from it. A non-cryptographic hash produces a fixed-length opaque byte digest over arbitrary input; a check code performs error detection over a constrained ASCII text alphabet and emits a short run of char values. The families are kept distinct by design rather than unified under one base type.
The streaming surface - Append(ReadOnlySpan<char>),
Reset(), and the two GetCurrentCheckDigits overloads - will nonetheless feel
familiar to anyone who has used a hash algorithm: input is accumulated, the computation can be restarted, and
reading the current check code is non-destructive and idempotent. That resemblance is incidental convenience, not a
shared contract. Concrete implementations document their empty-body behavior.
Instances are not thread-safe. Each thread that needs a running check should construct its own instance.
important
Check-digit algorithms are error-detection primitives, not cryptographic functions. They must not be used for password hashing, digital signatures, or integrity validation in security-sensitive applications.
Constructors
MultiCharCheckDigitAlgorithm()
Initializes a new instance of the MultiCharCheckDigitAlgorithm class.
protected MultiCharCheckDigitAlgorithm()
Properties
CheckLength
Gets the fixed number of decimal-digit characters emitted as the trailing check code.
public override abstract int CheckLength { get; }
Property Value
- int
A positive integer; for example,
2for ISO 7064 MOD 97-10.
InputAlphabet
Gets the subset of ASCII from which this algorithm accepts body characters.
public abstract CheckDigitInputAlphabet InputAlphabet { get; }
Property Value
- CheckDigitInputAlphabet
The declared input alphabet.
Methods
GetCurrentCheckDigits()
Returns the current check code as a newly allocated string.
public string GetCurrentCheckDigits()
Returns
- string
A string of length CheckLength containing the trailing check characters.
Remarks
Allocating convenience wrapper over GetCurrentCheckDigits(Span<char>). Prefer the span overload in hot paths where the allocation is undesirable.
GetCurrentCheckDigits(Span<char>)
Writes the current check code into the supplied destination span.
public abstract int GetCurrentCheckDigits(Span<char> destination)
Parameters
destinationSpan<char>The span to receive the trailing check characters. Must be at least CheckLength in length.
Returns
- int
The number of characters written, always equal to CheckLength.
Remarks
This call is non-destructive; the running state is unaffected and the method may be invoked any number of times with identical results between appends.
Exceptions
- ArgumentException
Thrown when
destinationis shorter than CheckLength.
GetCurrentCheckValue()
Returns the check value computed for the body absorbed since the last Reset() (or since construction) as a newly allocated string.
public override sealed string GetCurrentCheckValue()
Returns
- string
A string of length CheckLength containing the check value.
Remarks
This call is non-destructive; the running state is unaffected and the method may be invoked any number of times
with identical results between appends. The single-character branches also expose the result as a
char via GetCurrentCheckDigit(), which avoids the string allocation.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |