1 package org.openslx.imagemaster.util;
3 import java.security.SecureRandom;
11 private static final String
lettersSpecial =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890+-$%&/()=?@";
12 private static final String
letters =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
13 private static final SecureRandom
random =
new SecureRandom();
22 public static String
generate(
int length,
boolean specialChars )
24 String used = ( specialChars ) ? lettersSpecial : letters;
26 for (
int i = 0; i < length; i++ ) {
27 int index = (int) ( random.nextDouble() * used.length() );
28 result += used.substring( index, index + 1 );
41 byte[] result =
new byte[ length ];
42 random.nextBytes( result );
Generate secure random strings.
static final String letters
static String generate(int length, boolean specialChars)
Generate a random string.
static final SecureRandom random
static final String lettersSpecial
static byte[] generateBinary(int length)
Generate random binary data.