feat(可回溯): appKey生成
修改appKey生成方式
This commit is contained in:
@@ -1,19 +1,24 @@
|
|||||||
package com.wabestway.recall.util;
|
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;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class ShortAppKeyGenerator {
|
public class ShortAppKeyGenerator {
|
||||||
private static final char[] BASE62_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".toCharArray();
|
private static final char[] BASE62_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".toCharArray();
|
||||||
|
|
||||||
public static String generate() {
|
public static String generate() {
|
||||||
UUID uuid = UUID.randomUUID();
|
String input = System.currentTimeMillis() + "";
|
||||||
long mostSigBits = uuid.getMostSignificantBits();
|
MessageDigest md = null;
|
||||||
long leastSigBits = uuid.getLeastSignificantBits();
|
try {
|
||||||
byte[] bytes = new byte[16];
|
md = MessageDigest.getInstance("MD5");
|
||||||
for (int i = 0; i < 8; i++) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
bytes[i] = (byte) (mostSigBits >>> (8 * (7 - i)));
|
throw new RuntimeException(e);
|
||||||
bytes[i + 8] = (byte) (leastSigBits >>> (8 * (7 - i)));
|
|
||||||
}
|
}
|
||||||
|
byte[] bytes = md.digest(input.getBytes());
|
||||||
return toBase62(bytes);
|
return toBase62(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,12 +37,13 @@ public class ShortAppKeyGenerator {
|
|||||||
long result = 0;
|
long result = 0;
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
result <<= 8;
|
result <<= 8;
|
||||||
result |= (bytes[i] & 0xFF);
|
result |= ((long) (bytes[i] & 0xFF));
|
||||||
}
|
|
||||||
for (int i = 8; i < 16; i++) {
|
|
||||||
result <<= 8;
|
|
||||||
result |= (bytes[i] & 0xFF);
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String appKey = generate();
|
||||||
|
System.out.println(appKey); // 输出:pT8bnL3ZTYqdBlUo
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user