@@ -0,0 +1,887 @@
+package us.kbase.auth2.cryptutils;%0A%0Aimport java.nio.charset.StandardCharsets;%0Aimport java.security.SecureRandom;%0Aimport java.util.Base64; // requires java 8%0A%0A%0Apublic class TokenGenerator %7B%0A%0A%09//TODO ONMOVE unit tests%0A%09//TODO ONMOVE docs%0A%09//TODO ONDB don't store the token, store a hash. For user requested tokens, associate a name. Store the date of creation & lifetime.%0A%09%0A%09// note SecureRandom is thread safe%0A%09private final SecureRandom random;%0A%09%0A%09public TokenGenerator() %7B%0A%09%09random = new SecureRandom();%0A%09%7D%0A%09%0A%09public String getToken() %7B%0A%09%09final byte%5B%5D b = new byte%5B21%5D; //168 bits so 28 b64 chars%0A%09%09random.nextBytes(b);%0A%09%09return new String(Base64.getEncoder().encode(b),%0A%09%09%09%09StandardCharsets.UTF_8);%0A%09%7D%0A%09%0A%09//TODO ONMOVE remove%0A%09public static void main(String%5B%5D args) throws Exception %7B%0A%09%09String t = new TokenGenerator().getToken();%0A%09%09%09%09%0A%09%09System.out.println(t + %22 %22 + t.length());%0A%09%7D%0A%7D%0A

Add token generator