Java Salt Value Create generateSalt()

Here you can find the source of generateSalt()

Description

Generates a radom salt

License

Open Source License

Return

the salt or null in error case

Declaration

public static byte[] generateSalt() 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;

public class Main {
    private static String SALT_ALGORITHM = "SHA1PRNG";
    private static int SALT_LENGTH = 8;

    /**// w  ww  . j a  v  a2  s . com
     * Generates a radom salt
     * 
     * @return the salt or null in error case
     */
    public static byte[] generateSalt() {
        try {
            SecureRandom random = SecureRandom.getInstance(SALT_ALGORITHM);

            byte[] salt = new byte[SALT_LENGTH];
            random.nextBytes(salt);

            return salt;
        } catch (final NoSuchAlgorithmException exc) {
            exc.printStackTrace();
        }

        return null;
    }
}

Related

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