Table of Contents

Interface ICipherTransform

Namespace
CryptoHives.Foundation.Security.Cryptography.Cipher
Assembly
CryptoHives.Foundation.Security.Cryptography.dll

Defines a cryptographic transform for symmetric cipher operations.

public interface ICipherTransform : ICryptoTransform, IDisposable
Inherited Members

Remarks

This interface extends ICryptoTransform to provide full compatibility with CryptoStream and other .NET cryptographic infrastructure, while also adding span-based overloads for zero-allocation scenarios.

Implementations should be created through CreateEncryptor() or CreateDecryptor() methods.

Properties

BlockSize

Gets the block size in bytes for this transform.

int BlockSize { get; }

Property Value

int

Remarks

For stream ciphers (ChaCha20) this returns 1, indicating byte-level operation. For block ciphers (AES) this returns the cipher block size (16 bytes).

Methods

Reset()

Resets the transform to its initial state.

void Reset()

Remarks

This allows reusing the transform for a new encryption/decryption operation with the same key but potentially different IV/nonce.

TransformBlock(ReadOnlySpan<byte>, Span<byte>)

Transforms the specified region of the input buffer and copies the result to the output buffer.

int TransformBlock(ReadOnlySpan<byte> input, Span<byte> output)

Parameters

input ReadOnlySpan<byte>

The input data to transform.

output Span<byte>

The buffer to receive the transformed data.

Returns

int

The number of bytes written to output.

Exceptions

ArgumentException

output is too small to hold the transformed data.

TransformFinalBlock(ReadOnlySpan<byte>, Span<byte>)

Transforms the final block of data, applying padding if necessary.

int TransformFinalBlock(ReadOnlySpan<byte> input, Span<byte> output)

Parameters

input ReadOnlySpan<byte>

The final input data to transform.

output Span<byte>

The buffer to receive the transformed data.

Returns

int

The number of bytes written to output.

Remarks

For encryption with padding modes, this method adds padding. For decryption, this method validates and removes padding. For AEAD modes, this method also handles authentication tag processing.