feat(可回溯): appKey生成

修改appKey生成方式
This commit is contained in:
BrandWang
2023-05-25 15:14:08 +08:00
parent 70b628b446
commit 825b010843
@@ -1,19 +1,24 @@
package com.wabestway.recall.util;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.UUID;
public class ShortAppKeyGenerator {
private static final char[] BASE62_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".toCharArray();
public static String generate() {
UUID uuid = UUID.randomUUID();
long mostSigBits = uuid.getMostSignificantBits();
long leastSigBits = uuid.getLeastSignificantBits();
byte[] bytes = new byte[16];
for (int i = 0; i < 8; i++) {
bytes[i] = (byte) (mostSigBits >>> (8 * (7 - i)));
bytes[i + 8] = (byte) (leastSigBits >>> (8 * (7 - i)));
String input = System.currentTimeMillis() + "";
MessageDigest md = null;
try {
md = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
byte[] bytes = md.digest(input.getBytes());
return toBase62(bytes);
}
@@ -32,12 +37,13 @@ public class ShortAppKeyGenerator {
long result = 0;
for (int i = 0; i < 8; i++) {
result <<= 8;
result |= (bytes[i] & 0xFF);
}
for (int i = 8; i < 16; i++) {
result <<= 8;
result |= (bytes[i] & 0xFF);
result |= ((long) (bytes[i] & 0xFF));
}
return result;
}
public static void main(String[] args) {
String appKey = generate();
System.out.println(appKey); // 输出:pT8bnL3ZTYqdBlUo
}
}