Here you can find the source of generateSalt(final Integer size)
http://stackoverflow.com/a/18268562/2648956
Parameter | Description |
---|---|
size | the size of the desired salt |
public static final String generateSalt(final Integer size)
//package com.java2s; //License from project: Open Source License import java.security.SecureRandom; import java.util.Random; public class Main { /**//from w ww.j av a 2 s. c o m * http://stackoverflow.com/a/18268562/2648956 * * @param size the size of the desired salt * @return the salt */ public static final String generateSalt(final Integer size) { final Random r = new SecureRandom(); byte[] salt = new byte[size / 2]; r.nextBytes(salt); return bytesToString(salt); } private static final String bytesToString(byte[] bytes) { StringBuffer encryptedUserID = new StringBuffer(); for (int i = 0; i < bytes.length; ++i) { String hex = Integer.toHexString(0xff & bytes[i]); if (hex.length() == 1) { encryptedUserID.append('0'); } encryptedUserID.append(hex); } return encryptedUserID.toString(); } }