public static String generate ( final int chars ) { final SecureRandom secureRandom = new SecureRandom ( ) ; final char [ ] buff = new char [ chars ] ; for ( int i = 0 ; i < chars ; ++ i ) { if ( i % 10 == 0 ) { secureRandom . setSeed ( secureRandom . nextLong ( ) ) ; } buff [ i ] = VALID_CHARACTERS [ secureRandom . nextInt ( VALID_CHARACTERS . length ) ] ; } return new String ( buff ) ; }
Generates a cryptographically secure API key of the specified length .