Java Salt Value Create generateSalt()

Here you can find the source of generateSalt()

Description

Generates secure random bytes.

License

Apache License

Return

a secure random salt with a size of bytes

Declaration

public static byte[] generateSalt() 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.security.SecureRandom;

public class Main {
    private static final int SALT_DEFAULT_SIZE = 32;

    /**/*from   w w w .  j av a 2s.  co m*/
     * Generates secure random bytes.
     *
     * @return a secure random salt with a size of {@value #SALT_DEFAULT_SIZE} bytes
     */
    public static byte[] generateSalt() {
        return generateSalt(SALT_DEFAULT_SIZE);
    }

    /**
     * Generates secure random bytes.
     *
     * @param saltSize
     *            the length for the salt in bytes
     * @return a secure random salt
     * @since 3.5
     */
    public static byte[] generateSalt(int saltSize) {

        SecureRandom r = new SecureRandom();
        byte[] salt = new byte[saltSize];
        r.nextBytes(salt);

        return salt;
    }
}

Related

  1. createSalt()
  2. createSalt(int byte_length)
  3. generateSalt()
  4. generateSalt()
  5. generateSalt()
  6. generateSalt()