Here you can find the source of getSaltDES(int snmpEngineBoots)
Parameter | Description |
---|---|
snmpEngineBoots | The (estimated) boots of the authoritative engine |
public final static byte[] getSaltDES(int snmpEngineBoots)
//package com.java2s; import java.util.*; public class Main { final static int SALT_LENGTH = 8; private static int salt_count = -1; /**//www . j a v a 2 s. c o m * 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. * * <p> * See "A Practical Guide to SNMPv3 and Network Management" section 6.8 * Privacy, p 194. * </p> * * @param snmpEngineBoots The (estimated) boots of the authoritative engine * @return The salt */ public final static byte[] getSaltDES(int snmpEngineBoots) { if (salt_count == -1) { // initialise the 2nd part of the salt java.util.Random rand = new Random(); salt_count = rand.nextInt(); } byte[] salt = new byte[SALT_LENGTH]; setBytesFromInt(salt, snmpEngineBoots, 0); setBytesFromInt(salt, salt_count, SALT_LENGTH / 2); salt_count++; return salt; } final static void setBytesFromInt(byte[] ret, int value, int offs) { int v = value; int j = offs; ret[j++] = (byte) ((v >>> 24) & 0xFF); ret[j++] = (byte) ((v >>> 16) & 0xFF); ret[j++] = (byte) ((v >>> 8) & 0xFF); ret[j++] = (byte) ((v >>> 0) & 0xFF); } }