Iban Class
Definition
- Namespace
- Bodu.IO.Hashing.CheckDigits
- Assembly
- Bodu.IO.Hashing.dll
- Package
- Bodu.IO.Hashing 1.0.0
- Source
- Iban.cs
Computes the two-digit check sequence of an International Bank Account Number (IBAN) using the ISO 13616 algorithm atop ISO 7064 MOD 97-10. This class cannot be inherited.
public sealed class Iban : MultiCharCheckDigitAlgorithm
- Inheritance
-
Iban
- Inherited Members
- Extension Methods
Examples
// Single-call computation - body is the country code followed by the BBAN.
string check = Iban.Compute("GBWEST12345698765432"); // "82"
// Full-sequence validation against the complete IBAN.
bool ok = Iban.IsValid("GB82WEST12345698765432"); // true
// Streaming use when the body is built up incrementally.
var algo = new Iban();
algo.Append("GBWEST12345698765432");
string code = algo.GetCurrentCheckDigits(); // "82"
Remarks
An IBAN takes the textual form CCDDBBAN where CC is a two-letter ISO 3166 country code, DD is a
two-digit check, and BBAN is the Basic Bank Account Number specific to the issuing country. To compute or
validate the check, the first four characters are moved to the end (BBAN + CC + DD), letters are expanded to
their numeric value ('A'=10 … 'Z'=35), and the resulting decimal string is evaluated under ISO 7064
MOD 97-10.
The streaming surface accepts a body comprising CC + BBAN - that is, the IBAN with the check placeholder
omitted - and produces the two check digits via GetCurrentCheckDigits(Span<char>).
IsValid(ReadOnlySpan<char>) accepts the complete CC + DD + BBAN form; whitespace and other
formatting characters are not tolerated, in keeping with ISO 13616 strict mode. Callers should normalize
textual IBANs (for example, by removing spaces) before passing them in.
Worked example. For the body "GBWEST12345698765432", the computed check is "82", and the
resulting IBAN "GB82WEST12345698765432" is therefore valid.
important
This algorithm is not cryptographically secure and should not be used for password hashing, digital signatures, or integrity validation in security-sensitive applications.
Constructors
Iban()
Initializes a new instance of the Iban class.
public Iban()
Fields
CheckDigits
The fixed check-code length of 2 decimal digits.
public const int CheckDigits = 2
Field Value
CountryCodeLength
The length of the country-code prefix (2 letters).
public const int CountryCodeLength = 2
Field Value
Properties
AlgorithmName
Gets the canonical name of the algorithm, suitable for diagnostic output and logging.
public override string AlgorithmName { get; }
Property Value
- string
A short, stable identifier such as
"Luhn","IBAN", or"ISO 7064 MOD 97-10".
CheckLength
Gets the fixed number of decimal-digit characters emitted as the trailing check code.
public override 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 override CheckDigitInputAlphabet InputAlphabet { get; }
Property Value
- CheckDigitInputAlphabet
The declared input alphabet.
Methods
Append(ReadOnlySpan<char>)
Absorbs the supplied characters into the running check-value state.
public override void Append(ReadOnlySpan<char> body)
Parameters
bodyReadOnlySpan<char>The characters to append. Each element must belong to the algorithm's accepted input alphabet. An empty span is a permitted no-op.
Exceptions
- ArgumentOutOfRangeException
Thrown when
bodycontains any character outside the algorithm's accepted input alphabet.
Compute(ReadOnlySpan<char>)
Computes the IBAN check digits for the supplied country-code-plus-BBAN body without allocating a streaming instance.
public static string Compute(ReadOnlySpan<char> body)
Parameters
bodyReadOnlySpan<char>The body characters - the complete IBAN minus its two-digit check sequence.
Returns
- string
The check code as a two-character string of ASCII decimal digits.
Exceptions
- ArgumentOutOfRangeException
Thrown when
bodycontains any character outside the alphanumeric uppercase alphabet.
GetCurrentCheckDigits(Span<char>)
Writes the current check code into the supplied destination span.
public override 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.
IsValid(ReadOnlySpan<char>)
Determines whether the supplied IBAN, in its contiguous (unspaced) canonical form, is consistent under ISO 13616.
public static bool IsValid(ReadOnlySpan<char> iban)
Parameters
ibanReadOnlySpan<char>The complete IBAN in canonical form - two-letter country code, two-digit check, then the BBAN - with no internal whitespace or formatting characters.
Returns
Reset()
Resets the algorithm to its initial state, discarding any characters previously absorbed.
public override void Reset()
Remarks
Equivalent in behavior to constructing a fresh instance of the same concrete type.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |