let's not use UUID.randomUUID().toString() for generating random strings
This commit is contained in:
parent
bee661a3f3
commit
1608cdb3b7
3 changed files with 37 additions and 20 deletions
|
@ -1,6 +1,8 @@
|
|||
package com.baseband.client;
|
||||
|
||||
|
||||
import de.tudbut.tools.Tools;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.UUID;
|
||||
|
@ -15,7 +17,7 @@ public class Key {
|
|||
|
||||
|
||||
public Key() {
|
||||
string = getRandomTicket();
|
||||
string = Tools.randomAlphanumericString(4096);
|
||||
}
|
||||
|
||||
public Key(String key) {
|
||||
|
@ -30,13 +32,6 @@ public class Key {
|
|||
this.debug = debug;
|
||||
}
|
||||
|
||||
private static String getRandomTicket() {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
for (int count = 0; count < 64; ++count) {
|
||||
buffer.append(UUID.randomUUID());
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
|
||||
public byte[] serializeObject(Object obj) {
|
||||
|
|
|
@ -14,7 +14,7 @@ public class Key {
|
|||
* Generates a random Key
|
||||
*/
|
||||
public Key() {
|
||||
string = getRandomTicket();
|
||||
string = randomAlphanumericString(4096);
|
||||
}
|
||||
|
||||
public Key(byte[] key) {
|
||||
|
@ -29,12 +29,23 @@ public class Key {
|
|||
this.debug = debug;
|
||||
}
|
||||
|
||||
private static String getRandomTicket() {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
for (int count = 0; count < 64; ++count) {
|
||||
buffer.append(UUID.randomUUID());
|
||||
public static int random(int lower, int upper) {
|
||||
return (int) (Math.floor(Math.random() * (upper - lower)) + lower);
|
||||
}
|
||||
return buffer.toString();
|
||||
public static String randomString(int length, String pool) {
|
||||
StringBuilder r = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
r.append(pool.charAt(random(0, pool.length())));
|
||||
}
|
||||
|
||||
return r.toString();
|
||||
}
|
||||
public static String randomAlphanumericString(int length) {
|
||||
String alphabet = "abcdefghijklmnopqrstuvwxyz";
|
||||
String pool = alphabet + alphabet.toUpperCase() + "0123456789";
|
||||
|
||||
return randomString(length, pool);
|
||||
}
|
||||
|
||||
public byte[] decryptByte(byte[] bytes) {
|
||||
|
|
|
@ -15,7 +15,7 @@ public class Key {
|
|||
* Generates a random Key
|
||||
*/
|
||||
public Key() {
|
||||
string = getRandomTicket();
|
||||
string = randomAlphanumericString(4096);
|
||||
}
|
||||
|
||||
public Key(String key) {
|
||||
|
@ -30,12 +30,23 @@ public class Key {
|
|||
this.debug = debug;
|
||||
}
|
||||
|
||||
private static String getRandomTicket() {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
for (int count = 0; count < 64; ++count) {
|
||||
buffer.append(UUID.randomUUID());
|
||||
public static int random(int lower, int upper) {
|
||||
return (int) (Math.floor(Math.random() * (upper - lower)) + lower);
|
||||
}
|
||||
return buffer.toString();
|
||||
public static String randomString(int length, String pool) {
|
||||
StringBuilder r = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
r.append(pool.charAt(random(0, pool.length())));
|
||||
}
|
||||
|
||||
return r.toString();
|
||||
}
|
||||
public static String randomAlphanumericString(int length) {
|
||||
String alphabet = "abcdefghijklmnopqrstuvwxyz";
|
||||
String pool = alphabet + alphabet.toUpperCase() + "0123456789";
|
||||
|
||||
return randomString(length, pool);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue