IBlockCipherModeTransform Interface
Definition
- Namespace
- Bodu.Security.Cryptography
- Assembly
- Bodu.Security.Cryptography.dll
- Package
- Bodu.Security.Cryptography 1.2.0
Defines a stateful block cipher mode transformation that applies a chaining strategy (such as ECB, CBC, CFB, OFB, or CTR) over a block cipher primitive.
public interface IBlockCipherModeTransform : IDisposable
- Inherited Members
- Extension Methods
Remarks
Implementations wrap an IBlockCipher and own any mode state required between calls, such as the evolving initialization vector, feedback register, or counter. Successive calls to Transform(ReadOnlySpan<byte>, Span<byte>, bool) continue the stream from the state left by the previous call.
Padding is not handled by this interface. Callers must align input to the cipher block size using an IPaddingStrategy before invoking Transform(ReadOnlySpan<byte>, Span<byte>, bool).
API surface. The library ships several implementations clustered into three groups:
- Classic confidentiality-only modes EcbModeTransform, CbcModeTransform, CfbModeTransform, OfbModeTransform, CtrModeTransform, CtsModeTransform.
- Disk-encryption modeXtsModeTransform.
- Authenticated modes (AEAD) Implement the richer IAeadBlockCipherModeTransform contract instead - GcmModeTransform , CcmModeTransform, EaxModeTransform, GcmSivModeTransform, OcbModeTransform, SivModeTransform.
Most callers should configure modes through Mode (which accepts a CipherModeKind and dispatches via BlockCipherModeFactory) rather than constructing this interface directly. Direct use is appropriate when wiring a custom block cipher into the existing mode infrastructure or building a higher-level construction on top.
Implementations are stateful and not thread-safe; share behind explicit synchronization, or allocate one per consumer. Most modes reset cleanly when constructed afresh - there is no in-place reset method on this interface.
Methods
Transform(ReadOnlySpan<byte>, Span<byte>, bool)
Transforms input under the mode's chaining strategy and writes the result to
output.
int Transform(ReadOnlySpan<byte> input, Span<byte> output, bool encrypt)
Parameters
inputReadOnlySpan<byte>The input data to transform. Its length must be a positive multiple of the underlying cipher block size.
outputSpan<byte>The destination span. Its length must be greater than or equal to the length of
input.encryptbool
Returns
- int
The number of bytes written to
output.
Exceptions
- ArgumentException
Thrown when
input's length is not a multiple of the block size or whenoutputis too small.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |