Class HashUtil


  • public class HashUtil
    extends java.lang.Object
    A util-Class for the creation of Hashes.
    • Constructor Summary

      Constructors 
      Constructor Description
      HashUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String getDigest​(java.io.InputStream inputStream)
      Calculates a base64 MD5 Hash for the content of an inputStream.
      static java.lang.String getDigest​(java.lang.String salt, java.io.InputStream inputStream)
      Calculates a base64 MD5 Hash for the content of an inputStream.
      • Methods inherited from class java.lang.Object

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

      • HashUtil

        public HashUtil()
    • Method Detail

      • getDigest

        public static java.lang.String getDigest​(java.io.InputStream inputStream)
                                          throws java.security.NoSuchAlgorithmException,
                                                 java.io.IOException
        Calculates a base64 MD5 Hash for the content of an inputStream.

        Mainly used for comparison of files. E.g. After PUTting a File to the Server, the Amazon S3-Client expects a base64 MD5 Hash, ETag, as part of the response Header to verify the validity of the transferred file.

        Parameters:
        inputStream - the InputStream.
        Returns:
        String Base64 MD5 Hash.
        Throws:
        java.security.NoSuchAlgorithmException - if no md5 can be found
        java.io.IOException - if InputStream can't be read
      • getDigest

        public static java.lang.String getDigest​(java.lang.String salt,
                                                 java.io.InputStream inputStream)
                                          throws java.security.NoSuchAlgorithmException,
                                                 java.io.IOException
        Calculates a base64 MD5 Hash for the content of an inputStream.

        Mainly used for comparison of files. E.g. After PUTting a File to the Server, the Amazon S3-Client expects a base64 MD5 Hash, ETag, as part of the response Header to verify the validity of the transferred file. For encrypted uploads, the returned hash may not be the same as the local client hash value.

        Parameters:
        salt - Optional salt to add to be digested, for simulating encryption dependent hashing.
        inputStream - the InputStream.
        Returns:
        String Base64 MD5 Hash.
        Throws:
        java.security.NoSuchAlgorithmException - if no md5 can be found.
        java.io.IOException - if InputStream can't be read.