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
inputKeybyte[]The input keying material.
messagebyte[]The message, i.e., the input data of the PRF.
Returns
- byte[]
128-bit (16 bytes) pseudo-random variable.
Exceptions
- ArgumentNullException
inputKeyormessageis 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
inputKeyReadOnlySpan<byte>The input keying material.
messageReadOnlySpan<byte>The message, i.e., the input data of the PRF.
destinationSpan<byte>The output buffer that represents the 128-bit (16 bytes) pseudo-random variable.
Exceptions
- ArgumentException
destinationis 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
passwordbyte[]The password used to derive the key.
saltbyte[]The key salt used to derive the key.
iterationsintThe number of iterations for the operation.
outputLengthintThe size of key to derive.
Returns
- byte[]
A byte array of length
outputLengththat is filled with pseudo-random key bytes.
Exceptions
- ArgumentNullException
passwordorsaltis null.- ArgumentOutOfRangeException
outputLengthis not zero or a positive value.- ArgumentOutOfRangeException
iterationsis 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
passwordReadOnlySpan<byte>The password used to derive the key.
saltReadOnlySpan<byte>The key salt used to derive the key.
iterationsintThe number of iterations for the operation.
outputLengthintThe size of key to derive.
Returns
- byte[]
A byte array of length
outputLengththat is filled with pseudo-random key bytes.
Exceptions
- ArgumentOutOfRangeException
outputLengthis not zero or a positive value.- ArgumentOutOfRangeException
iterationsis 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
passwordReadOnlySpan<byte>The password used to derive the key.
saltReadOnlySpan<byte>The key salt used to derive the key.
destinationSpan<byte>The buffer to fill with a derived key.
iterationsintThe number of iterations for the operation.
Exceptions
- ArgumentOutOfRangeException
iterationsis 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
passwordReadOnlySpan<char>The password used to derive the key.
saltReadOnlySpan<byte>The key salt used to derive the key.
iterationsintThe number of iterations for the operation.
outputLengthintThe size of key to derive.
Returns
- byte[]
A byte array of length
outputLengththat 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
passwordcontains text that cannot be converted to UTF8.- ArgumentOutOfRangeException
outputLengthis not zero or a positive value.- ArgumentOutOfRangeException
iterationsis 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
passwordReadOnlySpan<char>The password used to derive the key.
saltReadOnlySpan<byte>The key salt used to derive the key.
destinationSpan<byte>The buffer to fill with a derived key.
iterationsintThe 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
passwordcontains text that cannot be converted to UTF8.- ArgumentOutOfRangeException
iterationsis 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
passwordstringThe password used to derive the key.
saltbyte[]The key salt used to derive the key.
iterationsintThe number of iterations for the operation.
outputLengthintThe size of key to derive.
Returns
- byte[]
A byte array of length
outputLengththat 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
passwordorsaltis null.- EncoderFallbackException
passwordcontains text that cannot be converted to UTF8.- ArgumentOutOfRangeException
outputLengthis not zero or a positive value.- ArgumentOutOfRangeException
iterationsis not a positive value.