Package com.jgcomptech.tools
Class SecurityTools.FileHashes
- java.lang.Object
-
- com.jgcomptech.tools.SecurityTools.FileHashes
-
- Enclosing class:
- SecurityTools
public static final class SecurityTools.FileHashes extends java.lang.Object
Contains methods dealing with hashing files.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
getFileHash(SecurityTools.HashType type, java.lang.String filename)
Read the file and calculate the checksum.static java.lang.String
getFileHash(SecurityTools.HashType type, java.lang.String filename, boolean toUpperCase)
Read the file and calculate the checksum.static byte[]
readFromFile(java.lang.String fileName)
Read saved hash file to byte array.static void
saveToFile(java.lang.String hash, java.lang.String fileName)
Save generated hash to the specified file.static void
saveToFile(java.security.Key key, java.lang.String fileName)
Save generated Key to the specified file.
-
-
-
Method Detail
-
getFileHash
public static java.lang.String getFileHash(SecurityTools.HashType type, java.lang.String filename) throws java.io.IOException
Read the file and calculate the checksum.- Parameters:
type
- the hash type to usefilename
- the file to read- Returns:
- the hex representation of the hash using uppercase chars
- Throws:
java.io.FileNotFoundException
- if the file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for readingjava.io.IOException
- if an I/O error occurs
-
getFileHash
public static java.lang.String getFileHash(SecurityTools.HashType type, java.lang.String filename, boolean toUpperCase) throws java.io.IOException
Read the file and calculate the checksum.- Parameters:
type
- the hash type to usefilename
- the file to readtoUpperCase
- if true returned hash will be all uppercase- Returns:
- the hex representation of the hash
- Throws:
java.io.FileNotFoundException
- if the file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for readingjava.io.IOException
- if an I/O error occurs
-
saveToFile
public static void saveToFile(java.lang.String hash, java.lang.String fileName) throws java.io.IOException
Save generated hash to the specified file.- Parameters:
fileName
- Filename to be saved tohash
- Hash to be saved- Throws:
java.io.FileNotFoundException
- if the file is a directory rather than a regular file, or for some other reason cannot be opened for writingjava.io.IOException
- if an I/O error occurs
-
saveToFile
public static void saveToFile(java.security.Key key, java.lang.String fileName) throws java.io.IOException
Save generated Key to the specified file.- Parameters:
fileName
- Filename to be saved tokey
- Key to be saved- Throws:
java.io.FileNotFoundException
- if the file is a directory rather than a regular file, or for some other reason cannot be opened for writingjava.io.IOException
- if an I/O error occurs
-
readFromFile
public static byte[] readFromFile(java.lang.String fileName) throws java.io.IOException
Read saved hash file to byte array.- Parameters:
fileName
- Filename to be read from- Returns:
- File contents as string
- Throws:
java.io.FileNotFoundException
- if the file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for readingjava.io.IOException
- if an I/O error occurs
-
-