Class HashID

java.lang.Object
org.aoju.bus.core.key.HashID

public class HashID extends Object
Hashids用于从数字(如YouTube和Bitly)生成短散列, 数据库id,将它们用作忘记密码散列、邀请码、存储碎片号
Since:
Java 17+
Author:
Kimi Liu
  • Field Details

    • MAX_NUMBER

      public static final long MAX_NUMBER
      Max number that can be encoded with Hashids.
      See Also:
  • Constructor Details

    • HashID

      public HashID()
    • HashID

      public HashID(String salt)
    • HashID

      public HashID(String salt, int minHashLength)
    • HashID

      public HashID(String salt, int minHashLength, String alphabet)
  • 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 - 数据中心ID
      maxWorkerId - 最大的机器节点ID
      Returns:
      the long
    • encode

      public String encode(long... numbers)
      Encrypt numbers to string
      Parameters:
      numbers - the numbers to encrypt
      Returns:
      the encrypt string
    • decode

      public long[] decode(String hash)
      Decrypt string to numbers
      Parameters:
      hash - the encrypt string
      Returns:
      decryped numbers
    • encodeHex

      public String encodeHex(String hexa)
      Encrypt hexa to string
      Parameters:
      hexa - the hexa to encrypt
      Returns:
      the encrypt string
    • decodeHex

      public String decodeHex(String hash)
      Decrypt string to numbers
      Parameters:
      hash - the encrypt string
      Returns:
      decryped numbers
    • getVersion

      public String getVersion()
      Get Hashid algorithm version.
      Returns:
      id algorithm version implemented.
    • getSalt

      public String getSalt()