We would like to know how to generates a random 160-bit-value and returns it as hex-encoded string.
import java.math.BigInteger; import java.security.SecureRandom; //from ww w . j av a 2 s.c om public class Main{ /** * Generates a random 160-bit-value and returns it as hex-encoded string. * @return 160 bit hex encoded random */ public static String generateSalt() { SecureRandom random = new SecureRandom(); byte[] salt = random.generateSeed(20); return String.format("%040x", new BigInteger(1, salt)); } }