NtpAuthenticationKey Class

A symmetric key shared by an NTP client and an NTP server, which authenticates the packets they exchange with a message authentication code (MAC), as defined by RFC 5905 and RFC 8573.

public sealed class NtpAuthenticationKey

Remarks

The key identifier and the key must be the same on both sides. With ntpd and chrony, they are a line of the keys file: 1 AES128CMAC 000102030405060708090a0b0c0d0e0f is new NtpAuthenticationKey(1, NtpAuthenticationAlgorithm.AesCmac, Convert.FromHexString("000102030405060708090a0b0c0d0e0f")).

Constructors

NameDescription
NtpAuthenticationKey(uint, NtpAuthenticationAlgorithm, ReadOnlySpan<byte>)Initializes a new instance of the NtpAuthenticationKey class.

NtpAuthenticationKey(uint, NtpAuthenticationAlgorithm, ReadOnlySpan<byte>)

NtpAuthenticationKey.cs

Initializes a new instance of the NtpAuthenticationKey class.

public NtpAuthenticationKey(uint keyId, NtpAuthenticationAlgorithm algorithm, ReadOnlySpan<byte> key)

Parameters

keyId uint
The key identifier, sent in every authenticated packet. It cannot be 0, which RFC 5905 reserves.
algorithm NtpAuthenticationAlgorithm
The MAC algorithm.
key ReadOnlySpan<byte>
The secret key. NtpAuthenticationAlgorithm.AesCmac requires exactly 16 bytes.

Exceptions

ArgumentOutOfRangeException
keyId is 0, or algorithm is not defined.
ArgumentException
key is empty, or does not have the size the algorithm requires.

Properties

NameDescription
AlgorithmGets the MAC algorithm.
KeyGets the secret key.
KeyIdGets the key identifier.

Gets the MAC algorithm.

public NtpAuthenticationAlgorithm Algorithm { get; }

Gets the secret key.

public ReadOnlyMemory<byte> Key { get; }

Property value

ReadOnlyMemory<byte>

Gets the key identifier.

public uint KeyId { get; }

Property value

uint