Java Salt Value Create getSaltDES(int snmpEngineBoots)

Here you can find the source of getSaltDES(int snmpEngineBoots)

Description

Returns the DES salt.

License

Open Source License

Parameter

Parameter Description
snmpEngineBoots The (estimated) boots of the authoritative engine

Return

The salt

Declaration

public final static byte[] getSaltDES(int snmpEngineBoots) 

Method Source Code


//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);
    }
}

Related

  1. generateSaltedSHAHash(String algorithm, String input, String salt)
  2. generateSaltOfLength(int length)
  3. getMd5Salt()
  4. getNewSalt()
  5. getSalt()
  6. getSaltedString(String in)
  7. getSaltString()