Skip to content

Commit 55f6ee0

Browse files
committed
feat: 注释规范化
1 parent 7b9abd2 commit 55f6ee0

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

src/main/java/top/meethigher/proxy/FastAes.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
public final class FastAes {
1616

1717
private static final String TRANSFORMATION = "AES/GCM/NoPadding";
18-
private static final int AES_KEY_LEN = 128; // bit
19-
private static final int GCM_TAG_LEN = 128; // bit
20-
private static final int GCM_IV_LEN = 12; // byte
18+
private static final int AES_KEY_LEN = 128; // bit
19+
private static final int GCM_TAG_LEN = 128; // bit
20+
private static final int GCM_IV_LEN = 12; // byte
2121

2222
private static final SecureRandom RAND = new SecureRandom();
2323

@@ -30,12 +30,15 @@ public final class FastAes {
3030
}
3131
});
3232

33-
private FastAes() {} // utility class
33+
private FastAes() {
34+
} // utility class
3435

3536
/* ---------------------------------- 对外 API ---------------------------------- */
3637

3738
/**
3839
* 随机生成 AES-128 密钥
40+
*
41+
* @return 密钥
3942
*/
4043
public static SecretKey generateKey() {
4144
try {
@@ -49,6 +52,9 @@ public static SecretKey generateKey() {
4952

5053
/**
5154
* 将原始密钥字节数组包装成 SecretKey
55+
*
56+
* @param rawKey 原始密钥字节数组
57+
* @return SecretKey
5258
*/
5359
public static SecretKey restoreKey(byte[] rawKey) {
5460
if (rawKey.length != AES_KEY_LEN / 8) {
@@ -59,6 +65,10 @@ public static SecretKey restoreKey(byte[] rawKey) {
5965

6066
/**
6167
* 加密:返回 byte[],格式为 IV(12B) + CipherText + Tag(16B)
68+
*
69+
* @param key 密钥
70+
* @param plain 原文
71+
* @return 密文字节数组
6272
*/
6373
public static byte[] encrypt(byte[] plain, SecretKey key) {
6474
try {
@@ -71,16 +81,20 @@ public static byte[] encrypt(byte[] plain, SecretKey key) {
7181
byte[] cipherText = cipher.doFinal(plain);
7282

7383
return ByteBuffer.allocate(iv.length + cipherText.length)
74-
.put(iv)
75-
.put(cipherText)
76-
.array();
84+
.put(iv)
85+
.put(cipherText)
86+
.array();
7787
} catch (Exception e) {
7888
throw new RuntimeException("Encrypt error", e);
7989
}
8090
}
8191

8292
/**
8393
* 解密:输入格式须为 IV(12B) + CipherText + Tag(16B)
94+
*
95+
* @param key 密钥
96+
* @param ivPlusCipherText 密文
97+
* @return 原文
8498
*/
8599
public static byte[] decrypt(byte[] ivPlusCipherText, SecretKey key) {
86100
try {
@@ -104,7 +118,6 @@ public static byte[] decrypt(byte[] ivPlusCipherText, SecretKey key) {
104118
}
105119
}
106120

107-
/* ----------------------------- 简易 Base64 封装 ----------------------------- */
108121

109122
public static String encryptToBase64(byte[] plain, SecretKey key) {
110123
return Base64.getEncoder().encodeToString(encrypt(plain, key));

src/main/java/top/meethigher/proxy/tcp/mux/Mux.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ public Mux(Vertx vertx, String secret) {
4545
}
4646

4747
/**
48-
* 将host与port通过英文冒号连接,返回加密base64串(无换行)
48+
* @param configuration mux通信配置信息
49+
* @return 返回configuration加密后的base64串(无换行)
4950
*/
5051
public Buffer aesBase64Encode(MuxConfiguration configuration) {
5152
String addr = configuration.toString();
@@ -55,7 +56,8 @@ public Buffer aesBase64Encode(MuxConfiguration configuration) {
5556
}
5657

5758
/**
58-
* 将加密内容还原
59+
* @param buffer 加密内容
60+
* @return buffer解密后的内容
5961
*/
6062
public MuxConfiguration aesBase64Decode(Buffer buffer) {
6163
TunnelMessageCodec.DecodedMessage decode = TunnelMessageCodec.decode(buffer);

src/main/java/top/meethigher/proxy/tcp/mux/ReverseTcpProxyMuxServer.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ protected void handleConnect(NetSocket src) {
4545

4646
/**
4747
* 根据{@code MuxMessage }建立后端连接,并将数据连接和后端连接进行绑定
48+
*
49+
* @param src muxclient与muxserver建立的连接
50+
* @param muxMsg mux通信配置消息
4851
*/
4952
protected void bindMuxConnections(NetSocket src, MuxMessageParser.MuxMessage muxMsg) {
5053
src.pause();

src/main/java/top/meethigher/proxy/tcp/tunnel/Tunnel.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ public void on(TunnelMessageType type, TunnelHandler tunnelHandler) {
7171

7272
/**
7373
* 返回加密base64串(无换行)
74+
* @param bodyBytes 原文
75+
* @return 密文
7476
*/
7577
public byte[] aesBase64Encode(byte[] bodyBytes) {
7678
SecretKey key = restoreKey(secret.getBytes(StandardCharsets.UTF_8));
@@ -79,6 +81,9 @@ public byte[] aesBase64Encode(byte[] bodyBytes) {
7981

8082
/**
8183
* 将加密内容还原
84+
*
85+
* @param bodyBytes 密文
86+
* @return 原文
8287
*/
8388
public byte[] aesBase64Decode(byte[] bodyBytes) {
8489
SecretKey key = restoreKey(secret.getBytes(StandardCharsets.UTF_8));

0 commit comments

Comments
 (0)