Start work on shortening event IDs

This commit is contained in:
NovaFox161
2018-01-03 07:00:07 -06:00
parent 93e9dfb78e
commit da585fd371

View File

@@ -11,6 +11,8 @@ import java.util.Random;
public class KeyGenerator {
private static char[] VALID_CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456879".toCharArray();
private static char[] VALID_CHARS_2 = "abcdefghijklmnopqrstuv0123456789".toCharArray();
// cs = cryptographically secure
@SuppressWarnings("SameParameterValue")
public static String csRandomAlphaNumericString(int numChars) {
@@ -27,4 +29,34 @@ public class KeyGenerator {
}
return new String(buff);
}
public static String generateEventId() {
SecureRandom secRand = new SecureRandom();
Random rand = new Random();
char[] buff = new char[9];
for (int i = 0; i < 9; ++i) {
// reseed rand once you've used up all available entropy bits
if ((i % 10) == 0) {
rand.setSeed(secRand.nextLong()); // 64 bits of random!
}
buff[i] = VALID_CHARS_2[rand.nextInt(VALID_CHARS_2.length)];
}
return "e" + new String(buff);
}
public static String generateAnnouncementId() {
SecureRandom secRand = new SecureRandom();
Random rand = new Random();
char[] buff = new char[9];
for (int i = 0; i < 9; ++i) {
// reseed rand once you've used up all available entropy bits
if ((i % 10) == 0) {
rand.setSeed(secRand.nextLong()); // 64 bits of random!
}
buff[i] = VALID_CHARS_2[rand.nextInt(VALID_CHARS_2.length)];
}
return "a" + new String(buff);
}
}