Java Utililty Methods Salt Value Create

List of utility methods to do Salt Value Create

Description

The list of methods to do Salt Value Create are organized into topic(s).

Method

byte[]generateSalt(int numBytes)
generate Salt
if (numBytes <= 0) {
    throw new IllegalArgumentException(String
            .format("numBytes argument must be a positive integer (1 or larger)", Long.valueOf(numBytes)));
byte[] bytes = new byte[numBytes];
random.nextBytes(bytes);
return bytes;
StringgenerateSaltAESPBKDF2()
This method is used for generate slat
SecureRandom random = new SecureRandom();
byte bytes[] = new byte[20];
random.nextBytes(bytes);
return new String(bytes);
byte[]generateSaltedPassword(final String password, byte[] salt, int iterationsCount, String hmacName)
Generates salted password.
Mac mac = createHmac(password.getBytes(StandardCharsets.US_ASCII), hmacName);
mac.update(salt);
mac.update(INT_1);
byte[] result = mac.doFinal();
byte[] previous = null;
for (int i = 1; i < iterationsCount; i++) {
    mac.update(previous != null ? previous : result);
    previous = mac.doFinal();
...
StringgenerateSaltedSHAHash(String algorithm, String input, String salt)
generate Salted SHA Hash
MessageDigest md = MessageDigest.getInstance(algorithm);
md.update(salt.getBytes());
byte byteData[] = md.digest(input.getBytes());
StringBuffer sb = new StringBuffer();
for (int i = 0; i < byteData.length; i++) {
    sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
return sb.toString();
...
StringgenerateSaltOfLength(int length)
Generates a salt (random alphanumeric string) of given length.
StringBuilder salt = new StringBuilder();
Random rnd = new Random();
while (salt.length() < length) {
    int index = rnd.nextInt(UPPERCASE_ALPHANUMERIC_CHARS.length());
    salt.append(UPPERCASE_ALPHANUMERIC_CHARS.charAt(index));
return salt.toString();
StringgetMd5Salt()
get Md Salt
return getRandomText(8);
StringgetNewSalt()
get New Salt
char[] validChars = "abcdefghijklmnoqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVXYZ0123456789".toCharArray();
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < 16; i++) {
    stringBuilder.append(validChars[(new Random()).nextInt(validChars.length - 1)]);
return stringBuilder.toString();
StringgetSalt()
get Salt
Random random = new Random();
StringBuilder sb = new StringBuilder("");
for (int i = 0; i < 6; i++) {
    sb.append(SALEARR[random.nextInt(26)]);
return sb.toString();
byte[]getSaltDES(int snmpEngineBoots)
Returns the DES salt.
if (salt_count == -1) {
    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++;
...
StringgetSaltedString(String in)

This method takes a string, adds a random salt to it, and returns it.

The random number generator for this method is low security, and should not be used for cryptographic purposes where unpredictability is paramount.

Generally, salts need not be unpredictable, as long as they are not often repeated.

return in + " " + getRandomHex();