Here you can find the source of generateSaltOfLength(int length)
Parameter | Description |
---|---|
length | of salt to be be generated |
public static String generateSaltOfLength(int length)
//package com.java2s; //License from project: Open Source License import java.util.Random; public class Main { private static final String UPPERCASE_ALPHANUMERIC_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; /**// ww w. jav a 2 s.c o m * Generates a salt (random alphanumeric string) of given length. * @param length of salt to be be generated * @return generated salt */ public static String generateSaltOfLength(int 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(); } }