Package utils.common
Class HashUtils
- java.lang.Object
-
- utils.common.HashUtils
-
public class HashUtils extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringSHA_256
-
Constructor Summary
Constructors Constructor Description HashUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringgenerateSecureRandomString(int length)Generates a random string that can be used for passwords or tokens https://stackoverflow.com/a/31260788/1278769static java.lang.StringgetChecksum(java.lang.String str)Uses MD5 to generate a 6 chars long checksum of a stringstatic longgetChecksum(java.nio.file.Path file)Uses Adler32 to calculate a checksum of a filestatic java.lang.StringgetHash(java.lang.String str, java.lang.String hashFunction)Calculates hash with the given hash function.static java.lang.StringgetHash(java.nio.file.Path file, java.lang.String hashFunction)Calculates hash for the given file.static java.lang.StringgetHashMD5(java.lang.String str)
-
-
-
Field Detail
-
SHA_256
public static final java.lang.String SHA_256
- See Also:
- Constant Field Values
-
-
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.IOExceptionCalculates 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.IOExceptionUses Adler32 to calculate a checksum of a file- Throws:
java.io.IOException
-
-