public static String generateRandomKey(int pLength) {
    int asciiFirst = 48;
    int asciiLast = 122;
    Integer[] exceptions = { 58,59,60,61,62,63,91,92,93,94,96 };

    List<Integer> exceptionsList = Arrays.asList(exceptions);
    SecureRandom random = new SecureRandom();
    StringBuilder builder = new StringBuilder();
    for (int i=0; i<pLength; i++) {
        int charIndex;
        do {
            charIndex = random.nextInt(asciiLast - asciiFirst + 1) + asciiFirst;
        }
        while (exceptionsList.contains(charIndex));

        builder.append((char) charIndex);
    }

    return builder.toString();
}
public static String generateRandomKey ( int pLength ) { int asciiFirst = 48 ; int asciiLast = 122 ; Integer [ ] exceptions = { 58 , 59 , 60 , 61 , 62 , 63 , 91 , 92 , 93 , 94 , 96 } ; List < Integer > exceptionsList = Arrays . asList ( exceptions ) ; SecureRandom random = new SecureRandom ( ) ; StringBuilder builder = new StringBuilder ( ) ; for ( int i = 0 ; i < pLength ; i ++ ) { int charIndex ; do { charIndex = random . nextInt ( asciiLast - asciiFirst + 1 ) + asciiFirst ; } while ( exceptionsList . contains ( charIndex ) ) ; builder . append ( ( char ) charIndex ) ; } return builder . toString ( ) ; }
generate a Random key
@param pLength
@return the reandom key with the given length