How do you generate a secure random (or pseudo-random) alphanumeric string in Java efficiently?
Generate a public key for an open-key encryption algorithm and convert the byte sequence to string via Base64 algorithm.
If you use Apache Commons Lang, the easiest way is
RandomStringUtils.random(20, 0, 0, true, true, null, new SecureRandom());
http://download.oracle.com/javase/6/docs/api/java/security/SecureRandom.html
From the Javadoc:
SecureRandom random = new SecureRandom();
byte bytes[] = new byte[20];
random.nextBytes(bytes);