Last active
December 31, 2015 00:29
-
-
Save roamingthings/7907530 to your computer and use it in GitHub Desktop.
Generate a random alphanumerical String like a password or token.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package de.roamingthings.crypto; | |
public class RandomToken { | |
private static final SecureRandom rand = new SecureRandom(); | |
public static String generateRandomToken(int bits) { | |
return new BigInteger(bits, rand).toString(32); | |
} | |
public static main(String[] args) { | |
String randomToken = generateRandomToken(130); | |
System.out.println(randomToken); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment