Overview | Package | Class | Tree | Deprecated | Index | Help
| SNMP Stack 4_12
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## uk.co.westhawk.snmp.util
Class SnmpUtilities

    java.lang.Object
      |
      +--uk.co.westhawk.snmp.util.SnmpUtilities

public class SnmpUtilities
extends java.lang.Object

This class contains utilities for key and authentication encoding. See RFC 2574.

Version:
  $Revision: 1.17 $ $Date: 2002/10/10 15:13:57 $
Author:
  Tim Panton

Constructor Summary
`SnmpUtilities()`

Method Summary
`static boolean` | `areBytesEqual(byte[] array1, byte[] array2)` Compaires two byte arrays and returns if they are equal.
`static byte[]` | `decrypt(byte[] encryptedText, byte[] salt, byte[] secretPrivacyKey)` Decryptes bytes using DES.
`static void` | `dumpBytes(java.lang.String headerStr, byte[] bytes)` Dumps (prints) the byte array.
`static byte[]` | `encrypt(byte[] plain, byte[] secretPrivacyKey, byte[] salt)` Encrypts bytes using DES.
`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[]` | `getInitialValue(byte[] secretPrivacyKey, byte[] salt)` Returns the DES initial value.
`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[]` | `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[]` | `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.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### SnmpUtilities

    public SnmpUtilities()

Method Detail

### getSnmpVersionString

    public static java.lang.String getSnmpVersionString(int version)

  Returns the String representation of the SNMP version number.
  Parameters:
    `version` - The version number
  Returns:
    The corresponding String.

### toBytes

    public static byte[] toBytes(java.lang.String hexStr)

  Converts a hexadecimal ASCII string to a byte array. The method is case insensitive, so F7 works as well as f7. The string should have the form F7d820 and should omit the '0x'. This method is the reverse of `toHexString`.
  Parameters:
    `hexStr` - The string representing a hexadecimal number
  Returns:
    the byte array of hexStr
  See Also:
    `toHexString(byte[])`

### dumpBytes

    public static void dumpBytes(java.lang.String headerStr,
                                 byte[] bytes)

  Dumps (prints) the byte array. Debug method.
  Parameters:
    `headerStr` - String that will be printed as header
    `bytes` - Bytes to be dumped as hex.

### toHexString

    public static java.lang.String toHexString(byte[] bytes)

  Converts a byte array to a hexadecimal ASCII string. The string will be in upper case and does not start with '0x'. This method is the reverse of `toBytes`.
  Parameters:
    `bytes` - The byte array
  Returns:
    The string representing the byte array
  See Also:
    `toBytes(String)`

### toHex

    public static java.lang.String toHex(int val)

  Converts one int to a hexadecimal ASCII string.
  Parameters:
    `val` - The integer
  Returns:
    The hex string

### areBytesEqual

    public static boolean areBytesEqual(byte[] array1,
                                        byte[] array2)

  Compaires two byte arrays and returns if they are equal.
  Parameters:
    `array1` - the first byte array
    `array2` - the second byte array
  Returns:
    whether they are equal of not.

### getLocalizedKeyMD5

    public 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. Described in RFC 2574.
  Parameters:
    `passwKey` - The password key
    `engineId` - The SNMP engine Id
  See Also:
    `SnmpContextv3.setUserAuthenticationPassword(String)`, `passwordToKeyMD5(String)`

### getLocalizedKeySHA1

    public 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.
  Parameters:
    `password` - The printable user password
    `engineId` - The SNMP engine Id
  See Also:
    `SnmpContextv3.setUserAuthenticationPassword(String)`

### passwordToKeySHA1

    public static byte[] passwordToKeySHA1(java.lang.String password)

  Converts the user's password to an authentication key using the SHA1 protocol. Note, this is not the same as generating the localized key as is described in RFC 2574.
  Parameters:
    `password` - The printable user password
  See Also:
    `SnmpContextv3.setUserAuthenticationPassword(String)`, `getLocalizedKeyMD5(byte[], java.lang.String)`

### passwordToKeyMD5

    public static byte[] passwordToKeyMD5(java.lang.String password)

  Converts the user's password to an authentication key using the MD5 protocol. Note, this is not the same as generating the localized key as is described in RFC 2574.
  Parameters:
    `password` - The printable user password
  See Also:
    `SnmpContextv3.setUserAuthenticationPassword(String)`, `getLocalizedKeyMD5(byte[], java.lang.String)`

### getFingerPrintMD5

    public static final byte[] getFingerPrintMD5(byte[] key,
                                                 byte[] message)

  Returns the 12 byte MD5 fingerprint.
  Parameters:
    `key` - The key
    `message` - The message
  See Also:
    `getFingerPrintSHA1(byte[], byte[])`

### getFingerPrintSHA1

    public static final byte[] getFingerPrintSHA1(byte[] key,
                                                  byte[] message)

  Returns the 12 byte SHA1 fingerprint.
  Parameters:
    `key` - The key
    `message` - The message
  See Also:
    `getFingerPrintMD5(byte[], byte[])`

### getSaltDES

    public static final byte[] getSaltDES(int snmpEngineBoots)

  Returns the DES salt. The "salt" value is generated by concatenating the 32-bit snmpEngineBoots value with a 32-bit counter value that the encryption engine maintains. This 32-bit counter will be initialised to some arbitrary value at boot time.

  See "A Practical Guide to SNMPv3 and Network Management" section 6.8 Privacy, p 194.

  Parameters:
    `snmpEngineBoots` - The (estimated) boots of the authoritative engine
  Returns:
    The salt

### getDESKey

    public static final byte[] getDESKey(byte[] secretPrivacyKey)
                                  throws PduException

  Returns the DES key. The 16-byte secret privacy key is made up of 8 bytes that make up the DES key and 8 bytes used as a preinitialisation vector.
  Parameters:
    `secretPrivacyKey` - The secret privacy key
  Returns:
    The key

### getInitialValue

    public static final byte[] getInitialValue(byte[] secretPrivacyKey,
                                               byte[] salt)
                                        throws PduException

  Returns the DES initial value. The 16-byte secret privacy key is made up of 8 bytes that make up the DES key and 8 bytes used as a preinitialisation vector. The initialization vector that is used by the DES algorithm is the result of the 8-byte preinitialisation vector XOR-ed with the 8-byte "salt".
  Parameters:
    `secretPrivacyKey` - The secret privacy key
    `salt` - The salt
  Returns:
    The initial value

### encrypt

    public static final byte[] encrypt(byte[] plain,
                                       byte[] secretPrivacyKey,
                                       byte[] salt)
                                throws EncodingException

  Encrypts bytes using DES. The plaintext needs to be a multiple of 8 octets. If it isn't, it will be padded at the end. This plaintext will be divided into 64-bit blocks. The plaintext for each block is XOR-ed with the "ciphertext" of the previous block. The result is then encrypted, added to the encrypted PDU portion of the message, and used as the "ciphertext" for the next block. For the first block, the initialization vector is used as the "ciphertext".
  Parameters:
    `plain` - The plain bytes
    `secretPrivacyKey` - The secret privacy key
    `salt` - The salt
  Returns:
    The encrypted bytes

### decrypt

    public static final byte[] decrypt(byte[] encryptedText,
                                       byte[] salt,
                                       byte[] secretPrivacyKey)
                                throws DecodingException

  Decryptes bytes using DES.
  - If the length of the data portion is not a multiple of 8 bytes, the message is discarded.
  - The first encrypted text block is decrypted. The decryption result is XOR-ed with the initialization vector, and the result is the first plaintext block.
  - The rest of the encrypted text blocks are treated similarly. They are decrypted, with the results being XOR-ed with the previous encrypted text block to obtain the plaintext block.
  Parameters:
    `encryptedText` - The encrypted text
    `salt` - The salt
    `secretPrivacyKey` - The secret privacy key
  Returns:
    The decrypted bytes

Overview | Package | Class | Tree | Deprecated | Index | Help
| SNMP Stack 4_12
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD