public class HashID extends Object
| Modifier and Type | Field and Description |
|---|---|
static long |
MAX_NUMBER
Max number that can be encoded with Hashids.
|
| Constructor and Description |
|---|
HashID() |
HashID(String salt) |
HashID(String salt,
int minHashLength) |
HashID(String salt,
int minHashLength,
String alphabet) |
| Modifier and Type | Method and Description |
|---|---|
static int |
checkedCast(long value) |
long[] |
decode(String hash)
Decrypt string to numbers
|
String |
decodeHex(String hash)
Decrypt string to numbers
|
String |
encode(long... numbers)
Encrypt numbers to string
|
String |
encodeHex(String hexa)
Encrypt hexa to string
|
static long |
getDataCenterId(long maxDatacenterId)
获取数据中心ID,依赖于本地网卡MAC地址
|
String |
getSalt() |
String |
getVersion()
Get Hashid algorithm version.
|
static long |
getWorkerId(long datacenterId,
long maxWorkerId)
获取机器ID,使用进程ID配合数据中心ID生成
依赖于本进程ID或进程名的Hash值
|
public static final long MAX_NUMBER
public HashID()
public HashID(String salt)
public HashID(String salt, int minHashLength)
public static int checkedCast(long value)
public static long getDataCenterId(long maxDatacenterId)
此算法来自于mybatis-plus#Sequence
maxDatacenterId - 最大的中心IDpublic static long getWorkerId(long datacenterId,
long maxWorkerId)
此算法来自于mybatis-plus#Sequence
datacenterId - 数据中心IDmaxWorkerId - 最大的机器节点IDpublic String encode(long... numbers)
numbers - the numbers to encryptpublic long[] decode(String hash)
hash - the encrypt stringpublic String encodeHex(String hexa)
hexa - the hexa to encryptpublic String decodeHex(String hash)
hash - the encrypt stringpublic String getVersion()
public String getSalt()
Copyright © 2022. All rights reserved.