Table of Contents

Lei Class

Definition

Namespace
Bodu.IO.Hashing.CheckDigits
Assembly
Bodu.IO.Hashing.dll
Package
Bodu.IO.Hashing 1.0.0
Source
Lei.cs

Computes the two-digit check sequence of a Legal Entity Identifier (LEI) as specified by ISO 17442. This class cannot be inherited.

public sealed class Lei : MultiCharCheckDigitAlgorithm
Inheritance
Lei
Inherited Members
Extension Methods

Examples

// Single-call computation against the 18-character body.
string check = Lei.Compute("54930084UKLVMY22DS");   // "16"

// Full-sequence validation.
bool ok = Lei.IsValid("54930084UKLVMY22DS16");      // true

// Streaming use when the body is built up incrementally.
var algo = new Lei();
algo.Append("54930084UKLVMY22DS");
string code = algo.GetCurrentCheckDigits();         // "16"

Remarks

A Legal Entity Identifier is a twenty-character alphanumeric code comprising an eighteen-character body followed by a two-digit check. The check is evaluated using ISO 7064 MOD 97-10 directly over the body, without the IBAN-style rearrangement: letters are expanded by value 'A'=10 … 'Z'=35, the resulting decimal string is folded through modulus ninety-seven, and the check is chosen so that the running remainder of the complete twenty-character sequence equals 1.

Worked example. For the body "54930084UKLVMY22DS", the computed check is "16", and the resulting LEI "54930084UKLVMY22DS16" 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

Lei()

Initializes a new instance of the Lei class.

public Lei()

Fields

BodyLength

The required body length of 18 characters.

public const int BodyLength = 18

Field Value

int

CheckDigits

The fixed check-code length of 2 decimal digits.

public const int CheckDigits = 2

Field Value

int

SequenceLength

The required full-sequence length of 20 characters.

public const int SequenceLength = 20

Field Value

int

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, 2 for 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

body ReadOnlySpan<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 body contains any character outside the algorithm's accepted input alphabet.

Compute(ReadOnlySpan<char>)

Computes the LEI check digits for the supplied body without allocating a streaming instance.

public static string Compute(ReadOnlySpan<char> body)

Parameters

body ReadOnlySpan<char>

The body characters. Each must be an ASCII decimal digit or uppercase Latin letter.

Returns

string

The check code as a two-character string of ASCII decimal digits.

Exceptions

ArgumentOutOfRangeException

Thrown when body contains 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

destination Span<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 destination is shorter than CheckLength.

IsValid(ReadOnlySpan<char>)

Determines whether the supplied sequence, comprising an eighteen-character body followed by a two-digit LEI check, is consistent under ISO 17442.

public static bool IsValid(ReadOnlySpan<char> valueIncludingCheck)

Parameters

valueIncludingCheck ReadOnlySpan<char>

The complete twenty-character LEI.

Returns

bool

true if the sequence is empty or evaluates as valid; otherwise, false - including the case where any character is outside the alphanumeric uppercase alphabet or the check characters are not decimal digits.

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

ProductVersions
.NET8, 10