Table of Contents

PaddingFactory Class

Definition

Namespace
Bodu.Security.Cryptography
Assembly
Bodu.Security.Cryptography.dll
Package
Bodu.Security.Cryptography 1.2.0
Source
PaddingFactory.cs

Creates IPaddingStrategy instances for the framework PaddingMode values and for the extended PaddingModeKind values.

public static class PaddingFactory
Inheritance
PaddingFactory
Inherited Members

Examples

// BCL-standard padding mode - covers PKCS7, Zeros, None, ANSI X.923, ISO 10126.
IPaddingStrategy pkcs7 = PaddingFactory.Create(PaddingMode.PKCS7);

// Extended padding mode - adds ISO/IEC 7816-4 ("one-and-zeros") used by smart cards and SHA-3.
IPaddingStrategy iso7816 = PaddingFactory.Create(PaddingModeKind.ISO7816_4);

// Apply on encryption.
byte[] padded = pkcs7.Pad(plaintext, blockSizeBits: 128);

// Remove on decryption - Unpad validates the trailer and throws CryptographicException
// if the padding is malformed.
byte[] stripped = pkcs7.Unpad(decrypted, blockSizeBits: 128);

Remarks

The factory dispatches a padding-scheme enumeration value to the matching IPaddingStrategy implementation. Used internally by every SymmetricAlgorithm in this library when its padding is configured.

Two overloads are provided. Create(PaddingMode) dispatches the BCL-standard PaddingMode values (PKCS7, Zeros, None, ANSI X.923, ISO 10126). Create(PaddingModeKind) additionally supports ISO7816_4, the "one-and-zeros" scheme used by smart cards and SHA-3 / Keccak - pick this overload when integrating with the extended PaddingModeKind superset.

Methods

Create(PaddingModeKind)

Creates a new IPaddingStrategy for the specified extended padding mode.

public static IPaddingStrategy Create(PaddingModeKind mode)

Parameters

mode PaddingModeKind

The padding scheme to apply. In addition to the five framework-enum values this overload supports ISO7816_4.

Returns

IPaddingStrategy

An IPaddingStrategy that implements the requested mode.

Exceptions

CryptographicException

Thrown if mode is not a supported padding scheme.

Create(PaddingMode)

Creates a new IPaddingStrategy for the specified framework padding mode.

public static IPaddingStrategy Create(PaddingMode mode)

Parameters

mode PaddingMode

The padding scheme to apply. Supported values are PKCS7, Zeros, None, ANSIX923 and ISO10126.

Returns

IPaddingStrategy

An IPaddingStrategy that implements the requested mode.

Exceptions

CryptographicException

Thrown if mode is not a supported padding scheme.

Applies to

ProductVersions
.NET8, 10

See Also