-
-
Save alejandrade/181cf8c49eef7bd84719c6e124fad330 to your computer and use it in GitHub Desktop.
A sample Java class that generates a URL safe random token
This file contains 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
import java.security.SecureRandom; | |
import java.util.Base64; | |
import java.util.Base64.Encoder; | |
public class RandomWebToken | |
{ | |
public static void main(String[] args) | |
{ | |
SecureRandom random = new SecureRandom(); | |
byte bytes[] = new byte[128]; | |
random.nextBytes(bytes); | |
Encoder encoder = Base64.getUrlEncoder().withoutPadding(); | |
String token = encoder.encodeToString(bytes); | |
System.out.println(token); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment