DbSchema激活

激活方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* @author 当我遇上你
* @公众号 当我遇上你
* @since 2020-07-01
*/
public class DbSchemaKeyGenerator {

public static void main(String[] args) {

String name = "cuishiying";
try {
String key = generateKey(name);
System.out.println("key: " + key);
} catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
e.printStackTrace();
}

}


private static String generateKey(String name) throws NoSuchAlgorithmException, UnsupportedEncodingException {
String salt = getSalt();
String encryptSource = "ax5" + name + "b52w" + salt + "vb3";
MessageDigest localMessageDigest = MessageDigest.getInstance("MD5");
String hash = formatToHex(localMessageDigest.digest(encryptSource.getBytes("UTF-8")));
return hash.substring(0, 4) + salt + hash.substring(4);
}


private static String formatToHex(byte[] paramArrayOfByte) {
StringBuilder localStringBuilder = new StringBuilder();
for (int m = 0; m < paramArrayOfByte.length; m++) {
if ((m % 32 == 0) && (m != 0)) {
localStringBuilder.append("\n");
}
String str = Integer.toHexString(paramArrayOfByte[m]);
if (str.length() < 2) {
str = "0" + str;
}
if (str.length() > 2) {
str = str.substring(str.length() - 2);
}
localStringBuilder.append(str);
}
return localStringBuilder.toString();
}

private static int random(int min, int max) {
return rand() % (max - min + 1) + min;
}

private static int rand() {
return new Random().nextInt(Integer.MAX_VALUE);
}

private static String getSalt() {
int r = random(10000, 30000);
return String.valueOf(r);
}
}

最后

本文到此结束,感谢阅读。如果您觉得不错,请关注公众号【当我遇上你】,您的支持是我写作的最大动力。