public class SnmpUtilities
extends java.lang.Object
Constructor and Description |
---|
SnmpUtilities() |
Modifier and Type | Method and Description |
---|---|
static byte[] |
AESdecrypt(byte[] ciphertext,
byte[] secretPrivacyKey,
int engineBoots,
int engineTime,
byte[] salt)
Decrypts using AES.
|
static byte[] |
AESencrypt(byte[] plaintext,
byte[] secretPrivacyKey,
int engineBoots,
int engineTime,
byte[] salt)
Encrypts bytes using AES.
|
static boolean |
areBytesEqual(byte[] array1,
byte[] array2)
Compaires two byte arrays and returns if they are equal.
|
static byte[] |
DESdecrypt(byte[] encryptedText,
byte[] salt,
byte[] secretPrivacyKey)
Decryptes bytes using DES.
|
static byte[] |
DESencrypt(byte[] plain,
byte[] secretPrivacyKey,
byte[] salt)
Encrypts bytes using DES.
|
static void |
dumpBytes(java.lang.String headerStr,
byte[] bytes)
Dumps (prints) the byte array.
|
static byte[] |
getAESInitialValue(int engineBoots,
int engineTime,
byte[] salt)
Returns the first 128 bits of the localized key Kul are used as the
AES encryption key.
|
static byte[] |
getAESKey(byte[] secretPrivacyKey)
Returns the first 128 bits of the localized key Kul are used as the
AES encryption key.
|
static byte[] |
getDESInitialValue(byte[] secretPrivacyKey,
byte[] salt)
Returns the DES initial value.
|
static byte[] |
getDESKey(byte[] secretPrivacyKey)
Returns the DES key.
|
static byte[] |
getFingerPrintMD5(byte[] key,
byte[] message)
Returns the 12 byte MD5 fingerprint.
|
static byte[] |
getFingerPrintSHA1(byte[] key,
byte[] message)
Returns the 12 byte SHA1 fingerprint.
|
static byte[] |
getLocalizedKeyMD5(byte[] passwKey,
java.lang.String engineId)
Converts the user's password and the SNMP Engine Id to the localized key
using the MD5 protocol.
|
static byte[] |
getLocalizedKeySHA1(byte[] passwKey,
java.lang.String engineId)
Converts the user's password and the SNMP Engine Id to the localized key
using the SHA protocol.
|
static byte[] |
getSaltAES()
Returns the AES salt.
|
static byte[] |
getSaltDES(int snmpEngineBoots)
Returns the DES salt.
|
static java.lang.String |
getSnmpVersionString(int version)
Returns the String representation of the SNMP version number.
|
static byte |
longToByte(long l)
Converts one long value to its byte value.
|
static byte[] |
longToByte(long[] l)
Converts an array of long values to its array of byte values.
|
static byte[] |
passwordToKeyMD5(java.lang.String password)
Converts the user's password to an authentication key using the MD5
protocol.
|
static byte[] |
passwordToKeySHA1(java.lang.String password)
Converts the user's password to an authentication key using the SHA1
protocol.
|
static byte[] |
toBytes(java.lang.String hexStr)
Converts a hexadecimal ASCII string to a byte array.
|
static java.lang.String |
toHex(int val)
Converts one int to a hexadecimal ASCII string.
|
static java.lang.String |
toHexString(byte[] bytes)
Converts a byte array to a hexadecimal ASCII string.
|
public static java.lang.String getSnmpVersionString(int version)
version
- The version numberpublic static byte[] toBytes(java.lang.String hexStr)
toHexString
.hexStr
- The string representing a hexadecimal numbertoHexString(byte[])
public static byte longToByte(long l) throws java.lang.IllegalArgumentException
l
- The long valuejava.lang.IllegalArgumentException
- when l is not in between 0 and 255.longToByte(long[])
public static byte[] longToByte(long[] l) throws java.lang.IllegalArgumentException
l
- The array of longsjava.lang.IllegalArgumentException
- when one of the longs is not in between 0 and 255.longToByte(long)
public static void dumpBytes(java.lang.String headerStr, byte[] bytes)
headerStr
- String that will be printed as headerbytes
- Bytes to be dumped as hex.public static java.lang.String toHexString(byte[] bytes)
toBytes
.bytes
- The byte arraytoBytes(String)
public static java.lang.String toHex(int val)
val
- The integerpublic static boolean areBytesEqual(byte[] array1, byte[] array2)
array1
- the first byte arrayarray2
- the second byte arraypublic static byte[] getLocalizedKeyMD5(byte[] passwKey, java.lang.String engineId)
passwKey
- The password keyengineId
- The SNMP engine IdSnmpContextv3Basis.setUserAuthenticationPassword(String)
,
passwordToKeyMD5(String)
public static byte[] getLocalizedKeySHA1(byte[] passwKey, java.lang.String engineId)
passwKey
- The printable user passwordengineId
- The SNMP engine IdSnmpContextv3Basis.setUserAuthenticationPassword(String)
public static byte[] passwordToKeySHA1(java.lang.String password)
password
- The printable user passwordSnmpContextv3Basis.setUserAuthenticationPassword(String)
,
getLocalizedKeyMD5(byte[], java.lang.String)
public static byte[] passwordToKeyMD5(java.lang.String password)
password
- The printable user passwordSnmpContextv3Basis.setUserAuthenticationPassword(String)
,
getLocalizedKeyMD5(byte[], java.lang.String)
public static final byte[] getFingerPrintMD5(byte[] key, byte[] message)
key
- The keymessage
- The messagegetFingerPrintSHA1(byte[], byte[])
public static final byte[] getFingerPrintSHA1(byte[] key, byte[] message)
key
- The keymessage
- The messagegetFingerPrintMD5(byte[], byte[])
public static final byte[] getSaltDES(int snmpEngineBoots)
See "A Practical Guide to SNMPv3 and Network Management" section 6.8 Privacy, p 194.
snmpEngineBoots
- The (estimated) boots of the authoritative enginepublic static byte[] getSaltAES()
public static final byte[] getDESKey(byte[] secretPrivacyKey) throws PduException
secretPrivacyKey
- The secret privacy keyPduException
public static final byte[] getAESKey(byte[] secretPrivacyKey) throws PduException
secretPrivacyKey
- The secret privacy keyPduException
public static final byte[] getDESInitialValue(byte[] secretPrivacyKey, byte[] salt) throws PduException
secretPrivacyKey
- The secret privacy keysalt
- The saltPduException
public static byte[] getAESInitialValue(int engineBoots, int engineTime, byte[] salt)
public static byte[] AESencrypt(byte[] plaintext, byte[] secretPrivacyKey, int engineBoots, int engineTime, byte[] salt) throws EncodingException
plaintext
- The plain bytessecretPrivacyKey
- The secret privacy keyengineBoots
- engineTime
- salt
- The saltEncodingException
public static final byte[] DESencrypt(byte[] plain, byte[] secretPrivacyKey, byte[] salt) throws EncodingException
plain
- The plain bytessecretPrivacyKey
- The secret privacy keysalt
- The saltEncodingException
public static final byte[] DESdecrypt(byte[] encryptedText, byte[] salt, byte[] secretPrivacyKey) throws DecodingException
encryptedText
- The encrypted textsalt
- The saltsecretPrivacyKey
- The secret privacy keyDecodingException
public static final byte[] AESdecrypt(byte[] ciphertext, byte[] secretPrivacyKey, int engineBoots, int engineTime, byte[] salt) throws DecodingException
ciphertext
- secretPrivacyKey
- The secret privacy keyengineBoots
- engineTime
- salt
- The saltDecodingException