Here you can find the source of generateSalt(int numberOfBytes)
public static String generateSalt(int numberOfBytes)
//package com.java2s; public class Main { private static final java.security.SecureRandom random = new java.security.SecureRandom(); private static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; /**//from w ww .jav a 2s . c o m * md5 128bit 16bytes * sha1 160bit 20bytes * sha256 256bit 32bytes * sha384 384bit 48bites * sha512 512bit 64bites */ public static String generateSalt(int numberOfBytes) { byte[] salt = new byte[numberOfBytes]; random.nextBytes(salt); return toHex(salt); } private static String toHex(byte[] bytes) { StringBuilder ret = new StringBuilder(bytes.length * 2); for (int i = 0; i < bytes.length; i++) { ret.append(HEX_DIGITS[(bytes[i] >> 4) & 0x0f]); ret.append(HEX_DIGITS[bytes[i] & 0x0f]); } return ret.toString(); } }