Table of Contents

Class AesCmacPrf128

Namespace
Dorssel.Security.Cryptography
Assembly
Dorssel.Security.Cryptography.AesExtra.dll

RFC 4615 key derivation algorithm (AES-CMAC-PRF-128) and the associated RFC 8018 password-based key derivation function (PBKDF2-AES-CMAC-PRF-128).

public static class AesCmacPrf128
Inheritance
AesCmacPrf128
Inherited Members

Remarks

AES-CMAC-PRF-128 is registered by IANA as PRF_AES128_CMAC.

Methods

DeriveKey(byte[], byte[])

Performs the AES-CMAC-PRF-128 pseudo-random function.

public static byte[] DeriveKey(byte[] inputKey, byte[] message)

Parameters

inputKey byte[]

The input keying material.

message byte[]

The message, i.e., the input data of the PRF.

Returns

byte[]

128-bit (16 bytes) pseudo-random variable.

Exceptions

ArgumentNullException

inputKey or message is null.

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

Performs the AES-CMAC-PRF-128 pseudo-random function.

public static void DeriveKey(ReadOnlySpan<byte> inputKey, ReadOnlySpan<byte> message, Span<byte> destination)

Parameters

inputKey ReadOnlySpan<byte>

The input keying material.

message ReadOnlySpan<byte>

The message, i.e., the input data of the PRF.

destination Span<byte>

The output buffer that represents the 128-bit (16 bytes) pseudo-random variable.

Exceptions

ArgumentException

destination is not exactly 16 bytes long.

Pbkdf2(byte[], byte[], int, int)

Creates a PBKDF2 derived key from password bytes using the AES-CMAC-PRF-128 pseudo-random function.

public static byte[] Pbkdf2(byte[] password, byte[] salt, int iterations, int outputLength)

Parameters

password byte[]

The password used to derive the key.

salt byte[]

The key salt used to derive the key.

iterations int

The number of iterations for the operation.

outputLength int

The size of key to derive.

Returns

byte[]

A byte array of length outputLength that is filled with pseudo-random key bytes.

Exceptions

ArgumentNullException

password or salt is null.

ArgumentOutOfRangeException

outputLength is not zero or a positive value.

ArgumentOutOfRangeException

iterations is not a positive value.

Pbkdf2(ReadOnlySpan<byte>, ReadOnlySpan<byte>, int, int)

Creates a PBKDF2 derived key from password bytes using the AES-CMAC-PRF-128 pseudo-random function.

public static byte[] Pbkdf2(ReadOnlySpan<byte> password, ReadOnlySpan<byte> salt, int iterations, int outputLength)

Parameters

password ReadOnlySpan<byte>

The password used to derive the key.

salt ReadOnlySpan<byte>

The key salt used to derive the key.

iterations int

The number of iterations for the operation.

outputLength int

The size of key to derive.

Returns

byte[]

A byte array of length outputLength that is filled with pseudo-random key bytes.

Exceptions

ArgumentOutOfRangeException

outputLength is not zero or a positive value.

ArgumentOutOfRangeException

iterations is not a positive value.

Pbkdf2(ReadOnlySpan<byte>, ReadOnlySpan<byte>, Span<byte>, int)

Fills a buffer with a PBKDF2 derived key using the AES-CMAC-PRF-128 pseudo-random function.

public static void Pbkdf2(ReadOnlySpan<byte> password, ReadOnlySpan<byte> salt, Span<byte> destination, int iterations)

Parameters

password ReadOnlySpan<byte>

The password used to derive the key.

salt ReadOnlySpan<byte>

The key salt used to derive the key.

destination Span<byte>

The buffer to fill with a derived key.

iterations int

The number of iterations for the operation.

Exceptions

ArgumentOutOfRangeException

iterations is not a positive value.

Pbkdf2(ReadOnlySpan<char>, ReadOnlySpan<byte>, int, int)

Creates a PBKDF2 derived key from a password using the AES-CMAC-PRF-128 pseudo-random function.

public static byte[] Pbkdf2(ReadOnlySpan<char> password, ReadOnlySpan<byte> salt, int iterations, int outputLength)

Parameters

password ReadOnlySpan<char>

The password used to derive the key.

salt ReadOnlySpan<byte>

The key salt used to derive the key.

iterations int

The number of iterations for the operation.

outputLength int

The size of key to derive.

Returns

byte[]

A byte array of length outputLength that is filled with pseudo-random key bytes.

Remarks

The password will be converted to bytes using the UTF8 encoding. For other encodings, convert the password string to bytes using the appropriate Encoding and use Pbkdf2(ReadOnlySpan<byte>, ReadOnlySpan<byte>, int, int).

Exceptions

EncoderFallbackException

password contains text that cannot be converted to UTF8.

ArgumentOutOfRangeException

outputLength is not zero or a positive value.

ArgumentOutOfRangeException

iterations is not a positive value.

Pbkdf2(ReadOnlySpan<char>, ReadOnlySpan<byte>, Span<byte>, int)

Fills a buffer with a PBKDF2 derived key using the AES-CMAC-PRF-128 pseudo-random function.

public static void Pbkdf2(ReadOnlySpan<char> password, ReadOnlySpan<byte> salt, Span<byte> destination, int iterations)

Parameters

password ReadOnlySpan<char>

The password used to derive the key.

salt ReadOnlySpan<byte>

The key salt used to derive the key.

destination Span<byte>

The buffer to fill with a derived key.

iterations int

The number of iterations for the operation.

Remarks

The password will be converted to bytes using the UTF8 encoding. For other encodings, convert the password string to bytes using the appropriate Encoding and use Pbkdf2(ReadOnlySpan<byte>, ReadOnlySpan<byte>, Span<byte>, int).

Exceptions

EncoderFallbackException

password contains text that cannot be converted to UTF8.

ArgumentOutOfRangeException

iterations is not a positive value.

Pbkdf2(string, byte[], int, int)

Creates a PBKDF2 derived key from a password using the AES-CMAC-PRF-128 pseudo-random function.

public static byte[] Pbkdf2(string password, byte[] salt, int iterations, int outputLength)

Parameters

password string

The password used to derive the key.

salt byte[]

The key salt used to derive the key.

iterations int

The number of iterations for the operation.

outputLength int

The size of key to derive.

Returns

byte[]

A byte array of length outputLength that is filled with pseudo-random key bytes.

Remarks

The password will be converted to bytes using the UTF8 encoding. For other encodings, convert the password string to bytes using the appropriate Encoding and use Pbkdf2(byte[], byte[], int, int).

Exceptions

ArgumentNullException

password or salt is null.

EncoderFallbackException

password contains text that cannot be converted to UTF8.

ArgumentOutOfRangeException

outputLength is not zero or a positive value.

ArgumentOutOfRangeException

iterations is not a positive value.

See Also