Class 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 use
        filename - 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 reading
        java.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 use
        filename - the file to read
        toUpperCase - 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 reading
        java.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 to
        hash - 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 writing
        java.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 to
        key - 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 writing
        java.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 reading
        java.io.IOException - if an I/O error occurs