How do i do that? Can\'t seems to find a way. Securerandom doesn\'t seems to allow me to specify bit size anywhere
Similar to the other answer with a minor detail
Random random = ThreadLocalRandom.current();
byte[] randomBytes = new byte[32];
random.nextBytes(randomBytes);
String encoded = Base64.getUrlEncoder().encodeToString(randomBytes)
Instead of simply using Base64 encoding, which can leave you with a '+' in the out, make sure it doesn't contain any characters which need to be further URL encoded.