程序包 com.ajaxjs.util

类 HashHelper

java.lang.Object
com.ajaxjs.util.HashHelper

public class HashHelper extends Object
  • 字段详细资料

  • 构造器详细资料

    • HashHelper

      public HashHelper(String algorithmName, byte[] input)
    • HashHelper

      public HashHelper(String algorithmName, String input)
  • 方法详细资料

    • getMessageDigest

      public byte[] getMessageDigest()
    • setKey

      public HashHelper setKey(String key)
    • setKeyBase64

      public HashHelper setKeyBase64(String key)
    • getMac

      public byte[] getMac()
      获取指定算法的 MAC 值(可设密钥)
      返回:
      生成的 MAC 值
    • hash

      public byte[] hash()
      Do hash
      返回:
      The hash value in bytes.
    • hashAsStr

      public String hashAsStr()
      Do hash
      返回:
      The hash value in hex string, lowercase.
    • hashAsBase64

      public String hashAsBase64(boolean isWithoutPadding)
      Get the result of hashed in BASE64
      参数:
      isWithoutPadding - 是否去掉末尾的 = 号
      返回:
      The result of hashed in BASE64
    • hashAsBase64

      public String hashAsBase64()
      Get the result of hashed in BASE64
      返回:
      The result of hashed in BASE64
    • md5

      public static String md5(String str)
      Generates MD5 hash value for a string. It's equivalent to Spring's DigestUtils.md5DigestAsHex()
      参数:
      str - Input string
      返回:
      MD5 hash value
    • getSHA1

      public static String getSHA1(String str)
      Generates SHA1 hash value for a string.
      参数:
      str - Input string
      返回:
      SHA1 hash value
    • getSHA256

      public static String getSHA256(String str)
      Generates SHA256 hash value for a string.
      参数:
      str - Input string
      返回:
      SHA256 hash value
    • getHmacMD5

      public static HashHelper getHmacMD5(String str, String key)
      Generates HMAC-MD5 hash value for a string.
      参数:
      str - Input string
      key - Key string
      返回:
      HMAC-MD5 hash value
    • getHmacSHA256

      public static String getHmacSHA256(String str, String key, boolean isWithoutPadding)
      Generates HMAC-SHA256 hash value for a string.
      参数:
      str - Input string
      key - Key string
      返回:
      HMAC-SHA256 hash value
    • calcFileMD5

      public static String calcFileMD5(InputStream in)
      Calculate the MD5 of a file.
      参数:
      in - The file stream.
      返回:
      The MD5 result in lowercase.
    • calcFileMD5

      public static String calcFileMD5(byte[] bytes)
      Calculate the MD5 of a file.
      参数:
      bytes - The file bytes.
      返回:
      The MD5 result in lowercase.