Package utils.common

Class HashUtils


  • public class HashUtils
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String SHA_256  
    • Constructor Summary

      Constructors 
      Constructor Description
      HashUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String generateSecureRandomString​(int length)
      Generates a random string that can be used for passwords or tokens https://stackoverflow.com/a/31260788/1278769
      static java.lang.String getChecksum​(java.lang.String str)
      Uses MD5 to generate a 6 chars long checksum of a string
      static long getChecksum​(java.nio.file.Path file)
      Uses Adler32 to calculate a checksum of a file
      static java.lang.String getHash​(java.lang.String str, java.lang.String hashFunction)
      Calculates hash with the given hash function.
      static java.lang.String getHash​(java.nio.file.Path file, java.lang.String hashFunction)
      Calculates hash for the given file.
      static java.lang.String getHashMD5​(java.lang.String str)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • HashUtils

        public HashUtils()
    • Method Detail

      • getHashMD5

        public static java.lang.String getHashMD5​(java.lang.String str)
      • getHash

        public static java.lang.String getHash​(java.lang.String str,
                                               java.lang.String hashFunction)
        Calculates hash with the given hash function. Uses ISO_8859_1 charset. Converts the byte array into an String of hexadecimal characters.
      • getHash

        public static java.lang.String getHash​(java.nio.file.Path file,
                                               java.lang.String hashFunction)
                                        throws java.io.IOException
        Calculates hash for the given file. Converts the byte array into a String of hexadecimal characters.
        Throws:
        java.io.IOException
      • generateSecureRandomString

        public static java.lang.String generateSecureRandomString​(int length)
        Generates a random string that can be used for passwords or tokens https://stackoverflow.com/a/31260788/1278769
      • getChecksum

        public static java.lang.String getChecksum​(java.lang.String str)
        Uses MD5 to generate a 6 chars long checksum of a string
      • getChecksum

        public static long getChecksum​(java.nio.file.Path file)
                                throws java.io.IOException
        Uses Adler32 to calculate a checksum of a file
        Throws:
        java.io.IOException