-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 支持移动云云空间加密分享
- Loading branch information
Showing
6 changed files
with
139 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package cn.qaiu.util; | ||
|
||
import java.security.SecureRandom; | ||
|
||
/** | ||
* @author <a href="https://qaiu.top">QAIU</a> | ||
* @date 2024/5/13 4:10 | ||
*/ | ||
public class UUIDUtil { | ||
|
||
public static String fjUuid() { | ||
return generateRandomString(21); | ||
} | ||
|
||
public static String generateRandomString(int length) { | ||
SecureRandom random = new SecureRandom(); | ||
byte[] randomBytes = new byte[length]; | ||
random.nextBytes(randomBytes); | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
for (byte b : randomBytes) { | ||
int value = b & 0x3F; // 63 in hexadecimal | ||
if (value < 36) { | ||
sb.append(Integer.toString(value, 36)); | ||
} else if (value < 62) { | ||
sb.append(Character.toUpperCase(Integer.toString(value - 26, 36).charAt(0))); | ||
} else if (value > 62) { | ||
sb.append("-"); | ||
} else { // value == 62 or 63 | ||
sb.append("_"); | ||
} | ||
} | ||
return sb.toString(); | ||
} | ||
} |