C# Class SnmpSharpNet.PrivacyDES

DES privacy protocol implementation class.
SNMP Version 3 DES privacy protocol implementation. DES requires an encryption key be provided of 16 bytes in length. Class will accept longer key values (which will be trimmed to 16 bytes) but both encrypt and decrypt operations will fail if key is shorter then required value length. Decryption operation depends on USM header privacyParameters field value which is generated by the Encrypt method. Make sure privacyParameters argument value is correctly inserted into the target packet to enable SNMP agent to decrypt the message.
Inheritance: IPrivacyProtocol
显示文件 Open project: griffina/SnmpSharpNet

Protected Properties

Property Type Description
_salt System.Int32

Public Methods

Method Description
Decrypt ( byte encryptedData, int offset, int length, byte key, int engineBoots, int engineTime, byte privacyParameters ) : byte[]

Decrypt DES encrypted ScopedPdu

Encrypt ( byte unencryptedData, int offset, int length, byte key, int engineBoots, int engineTime, byte &privacyParameters, IAuthenticationDigest authDigest ) : byte[]

Encrypt ScopedPdu using DES encryption protocol

ExtendShortKey ( byte shortKey, byte password, byte engineID, IAuthenticationDigest authProtocol ) : byte[]

Operation not used by DES. Key length has to be 16 bytes of encryption/decryption operation will fail. When called, shortKey is returned.

GetEncryptedLength ( int scopedPduLength ) : int

Get final encrypted length

PasswordToKey ( byte secret, byte engineId, IAuthenticationDigest authProtocol ) : byte[]

Convert privacy password into encryption key using packet authentication hash.

PrivacyDES ( ) : System

Standard constructor.

Protected Methods

Method Description
NextSalt ( ) : int

Returns next salt value.

Private Methods

Method Description
GetIV ( byte privacyKey, byte salt ) : byte[]

Generate IV from the privacy key and salt value returned by GetSalt method.

GetKey ( byte privacyPassword ) : byte[]

Extract and return DES encryption key. Privacy password is 16 bytes in length. Only the first 8 bytes are used as DES password. Remaining 8 bytes are used as pre-IV value.

GetSalt ( int engineBoots ) : byte[]

Get DES encryption salt value. Salt value is generated by concatenating engineBoots value with the random integer value.

Method Details

Decrypt() public method

Decrypt DES encrypted ScopedPdu
Thrown when encrypted data is null or length == 0 Thrown when encryption key length is less then 32 byte or if privacy parameters /// argument is null or length other then 8 bytes
public Decrypt ( byte encryptedData, int offset, int length, byte key, int engineBoots, int engineTime, byte privacyParameters ) : byte[]
encryptedData byte Source data buffer
offset int Offset within the buffer to start decryption process
length int Length of data to decrypt
key byte Decryption key. Key length has to be 32 bytes in length or longer (bytes beyond 32 bytes are ignored).
engineBoots int Authoritative engine boots value
engineTime int Authoritative engine time value
privacyParameters byte Privacy parameters extracted from USM header
return byte[]

Encrypt() public method

Encrypt ScopedPdu using DES encryption protocol
Thrown when encryption key is null or length of the encryption key is too short.
public Encrypt ( byte unencryptedData, int offset, int length, byte key, int engineBoots, int engineTime, byte &privacyParameters, IAuthenticationDigest authDigest ) : byte[]
unencryptedData byte Unencrypted ScopedPdu byte array
offset int Offset to start encryption
length int Length of data to encrypt
key byte Encryption key. Key has to be at least 32 bytes is length
engineBoots int Authoritative engine boots value
engineTime int Authoritative engine time value. Not used for DES
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
authDigest IAuthenticationDigest Authentication digest class reference. Not used by DES and can be null.
return byte[]

ExtendShortKey() public method

Operation not used by DES. Key length has to be 16 bytes of encryption/decryption operation will fail. When called, shortKey is returned.
public ExtendShortKey ( byte shortKey, byte password, byte engineID, IAuthenticationDigest authProtocol ) : byte[]
shortKey byte Encryption key
password byte Privacy password
engineID byte Authoritative engine id
authProtocol IAuthenticationDigest Authentication protocol class instance
return byte[]

GetEncryptedLength() public method

Get final encrypted length
public GetEncryptedLength ( int scopedPduLength ) : int
scopedPduLength int BER encoded ScopedPdu data length
return int

NextSalt() protected method

Returns next salt value.
protected NextSalt ( ) : int
return int

PasswordToKey() public method

Convert privacy password into encryption key using packet authentication hash.
Thrown when key size is shorter then MinimumKeyLength
public PasswordToKey ( byte secret, byte engineId, IAuthenticationDigest authProtocol ) : byte[]
secret byte Privacy user secret
engineId byte Authoritative engine id of the snmp agent
authProtocol IAuthenticationDigest Authentication protocol
return byte[]

PrivacyDES() public method

Standard constructor.
public PrivacyDES ( ) : System
return System

Property Details

_salt protected_oe property

Internal salt value. As per RFC standard, salt value is initialized in the constructor and incremented by 1 for each subsequent packet.
protected Int32,System _salt
return System.Int32