Table of Contents

Class DESPrivacyProvider

Namespace
Lextm.SharpSnmpLib.Security
Assembly
SharpSnmpLib.dll

Privacy provider for DES.

[Obsolete("DES is no longer secure. Please use a more secure provider.")]
public sealed class DESPrivacyProvider : IPrivacyProvider
Inheritance
DESPrivacyProvider
Implements
Inherited Members
Extension Methods

Remarks

Ported from SNMP#NET PrivacyDES class.

Constructors

DESPrivacyProvider(OctetString, IAuthenticationProvider)

Initializes a new instance of the DESPrivacyProvider class.

public DESPrivacyProvider(OctetString phrase, IAuthenticationProvider auth)

Parameters

phrase OctetString

The phrase.

auth IAuthenticationProvider

The authentication provider.

Properties

AuthenticationProvider

Corresponding IAuthenticationProvider.

public IAuthenticationProvider AuthenticationProvider { get; }

Property Value

IAuthenticationProvider

EngineIds

Engine IDs.

public ICollection<OctetString>? EngineIds { get; set; }

Property Value

ICollection<OctetString>

Remarks

This is an optional field, and only used by TRAP v2 authentication.

IsSupported

Verifies if the provider is supported.

public static bool IsSupported { get; }

Property Value

bool

MaximumKeyLength

Return maximum encryption/decryption key length. For DES, returned value is 16.

DES protocol itself requires an 8 byte key. Additional 8 bytes are used for generating the encryption IV. For encryption itself, first 8 bytes of the key are used.

public static int MaximumKeyLength { get; }

Property Value

int

MinimumKeyLength

Returns minimum encryption/decryption key length. For DES, returned value is 16.

DES protocol itself requires an 8 byte key. Additional 8 bytes are used for generating the encryption IV. For encryption itself, first 8 bytes of the key are used.

public static int MinimumKeyLength { get; }

Property Value

int

PrivacyParametersLength

Returns the length of privacyParameters USM header field. For DES, field length is 8.

public static int PrivacyParametersLength { get; }

Property Value

int

Salt

Gets the salt.

public OctetString Salt { get; }

Property Value

OctetString

The salt.

UseEcbEncryption

Flag to force using old ECB cipher mode encryption.

public static bool UseEcbEncryption { get; set; }

Property Value

bool

UseLegacy

Flag to force using legacy encryption/decryption code on .NET 6.

public static bool UseLegacy { get; set; }

Property Value

bool

Methods

Decrypt(ISnmpData, SecurityParameters)

Decrypts the specified data.

public ISnmpData Decrypt(ISnmpData data, SecurityParameters parameters)

Parameters

data ISnmpData

The data.

parameters SecurityParameters

The parameters.

Returns

ISnmpData

Decrypt(byte[], byte[], byte[])

Decrypt DES encrypted scoped PDU.

public static byte[] Decrypt(byte[] encryptedData, byte[] key, byte[] privacyParameters)

Parameters

encryptedData byte[]

Source data buffer

key byte[]

Decryption key. Key length has to be 32 bytes in length or longer (bytes beyond 32 bytes are ignored).

privacyParameters byte[]

Privacy parameters extracted from USM header

Returns

byte[]

Decrypted byte array

Exceptions

ArgumentNullException

Thrown when encrypted data is null or length == 0

ArgumentOutOfRangeException

Thrown when encryption key length is less then 32 byte or if privacy parameters argument is null or length other then 8 bytes

Encrypt(ISnmpData, SecurityParameters)

Encrypts the specified scope.

public ISnmpData Encrypt(ISnmpData data, SecurityParameters parameters)

Parameters

data ISnmpData

The scope data.

parameters SecurityParameters

The parameters.

Returns

ISnmpData

Encrypt(byte[], byte[], byte[])

Encrypt scoped PDU using DES encryption protocol

public static byte[] Encrypt(byte[] unencryptedData, byte[] key, byte[] privacyParameters)

Parameters

unencryptedData byte[]

Unencrypted scoped PDU byte array

key byte[]

Encryption key. Key has to be at least 32 bytes is length

privacyParameters byte[]

Privacy parameters out buffer. This field will be filled in with information required to decrypt the information. Output length of this field is 8 bytes and space has to be reserved in the USM header to store this information

Returns

byte[]

Encrypted byte array

Exceptions

ArgumentOutOfRangeException

Thrown when encryption key is null or length of the encryption key is too short.

PasswordToKey(byte[], byte[])

Passwords to key.

public byte[] PasswordToKey(byte[] secret, byte[] engineId)

Parameters

secret byte[]

The secret.

engineId byte[]

The engine identifier.

Returns

byte[]

ToString()

Returns a string that represents this object.

public override string ToString()

Returns

string