Package org.aoju.bus.core.key
Class HashID
java.lang.Object
org.aoju.bus.core.key.HashID
Hashids用于从数字(如YouTube和Bitly)生成短散列,
数据库id,将它们用作忘记密码散列、邀请码、存储碎片号
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longMax number that can be encoded with Hashids. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intcheckedCast(long value) long[]Decrypt string to numbersDecrypt string to numbersencode(long... numbers) Encrypt numbers to stringEncrypt hexa to stringstatic longgetDataCenterId(long maxDatacenterId) 获取数据中心ID,依赖于本地网卡MAC地址getSalt()Get Hashid algorithm version.static longgetWorkerId(long datacenterId, long maxWorkerId) 获取机器ID,使用进程ID配合数据中心ID生成 依赖于本进程ID或进程名的Hash值
-
Field Details
-
MAX_NUMBER
public static final long MAX_NUMBERMax number that can be encoded with Hashids.- See Also:
-
-
Constructor Details
-
HashID
public HashID() -
HashID
-
HashID
-
HashID
-
-
Method Details
-
checkedCast
public static int checkedCast(long value) -
getDataCenterId
public static long getDataCenterId(long maxDatacenterId) 获取数据中心ID,依赖于本地网卡MAC地址此算法来自于mybatis-plus#Sequence
- Parameters:
maxDatacenterId- 最大的中心ID- Returns:
- 数据中心ID
-
getWorkerId
public static long getWorkerId(long datacenterId, long maxWorkerId) 获取机器ID,使用进程ID配合数据中心ID生成 依赖于本进程ID或进程名的Hash值此算法来自于mybatis-plus#Sequence
- Parameters:
datacenterId- 数据中心IDmaxWorkerId- 最大的机器节点ID- Returns:
- the long
-
encode
Encrypt numbers to string- Parameters:
numbers- the numbers to encrypt- Returns:
- the encrypt string
-
decode
Decrypt string to numbers- Parameters:
hash- the encrypt string- Returns:
- decryped numbers
-
encodeHex
Encrypt hexa to string- Parameters:
hexa- the hexa to encrypt- Returns:
- the encrypt string
-
decodeHex
Decrypt string to numbers- Parameters:
hash- the encrypt string- Returns:
- decryped numbers
-
getVersion
Get Hashid algorithm version.- Returns:
- id algorithm version implemented.
-
getSalt
-