类 HashUtil

java.lang.Object
com.tlcsdm.core.util.HashUtil

public class HashUtil extends Object
常用的基本的关于编码和解码的函数的集合.
作者:
unknowIfGuestInDream
  • 字段详细资料

    • HASH_MD5

      public static final String HASH_MD5
      散列算法-MD5.
      另请参阅:
    • HASH_SHA1

      public static final String HASH_SHA1
      散列算法-SHA1.
      另请参阅:
    • HASH_SHA256

      public static final String HASH_SHA256
      散列算法-SHA256.
      另请参阅:
    • HEX

      private static final char[] HEX
  • 构造器详细资料

    • HashUtil

      private HashUtil()
  • 方法详细资料

    • hash

      public static String hash(String algorithm, byte[] bytes) throws NoSuchAlgorithmException
      字节数组散列.
      参数:
      algorithm - 散列算法
      bytes - 被散列的字节数组
      返回:
      散列结果,全小写字母
      抛出:
      NoSuchAlgorithmException - 当未找到指定的散列算法时抛出异常
    • hash

      public static String hash(String algorithm, File file) throws IOException, NoSuchAlgorithmException
      文件散列.
      参数:
      algorithm - 散列算法
      file - 被散列的文件
      返回:
      散列结果,全小写字母
      抛出:
      IOException - 当文件未找到或者输入输出时错误时抛出异常
      NoSuchAlgorithmException - 当未找到指定的散列算法时抛出异常
    • bytesToHex

      public static String bytesToHex(byte[] bytes)
      将字节数组转换成16进制字符串.
      参数:
      bytes - 要转换的字节数组
      返回:
      转换后的字符串,全小写字母
    • md5

      @Nullable public static String md5(String str)
      字符串MD5散列.
      参数:
      str - 被散列的字符串
      返回:
      散列结果,全小写字母
    • md5

      @Nullable public static String md5(File file)
      文件MD5散列.
      参数:
      file - 被散列的文件
      返回:
      散列结果,全小写字母
    • sha1

      @Nullable public static String sha1(String str)
      字符串SHA1散列.
      参数:
      str - 被散列的字符串
      返回:
      散列结果,全小写字母
    • sha1

      @Nullable public static String sha1(File file)
      文件SHA1散列.
      参数:
      file - 被散列的文件
      返回:
      散列结果,全小写字母