Class CryptoHashUtil


  • public final class CryptoHashUtil
    extends java.lang.Object
    This util class provides a fassade to the cryptographic hash functions of the java API.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      byte[] createHash​(java.lang.String algorithm, byte[] in)
      Creates an message digest of the given algorithm for the given input.
      byte[] createHash​(java.lang.String provider, java.lang.String algorithm, byte[] in)
      Creates an message digest of the given algorithm for the given input
      byte[] createHashWithKey​(java.lang.String provider, byte[] inputKey, byte[] in)
      Creates an message digest of the given algorithm for the given input
      static CryptoHashUtil getInstance()
      Get the instance
      byte[] md5​(byte[] in)
      Creates an MD5 message digest for the given input.
      byte[] sha1​(byte[] in)
      Creates an SHA1 message digest for the given input.
      byte[] sha256​(byte[] in)
      Creates an SHA-256 message digest for the given input.
      byte[] sha512​(byte[] in)
      Creates an SHA-512 message digest for the given input.
      • Methods inherited from class java.lang.Object

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

      • getInstance

        public static CryptoHashUtil getInstance()
        Get the instance
        Returns:
        the instance
      • md5

        public byte[] md5​(byte[] in)
                   throws java.security.GeneralSecurityException
        Creates an MD5 message digest for the given input.
        Parameters:
        in - the input
        Returns:
        the md5 message digest for the input
        Throws:
        java.security.GeneralSecurityException - in case of error
      • sha1

        public byte[] sha1​(byte[] in)
                    throws java.security.GeneralSecurityException
        Creates an SHA1 message digest for the given input.
        Parameters:
        in - the input
        Returns:
        the SHA1 message digest for the input
        Throws:
        java.security.GeneralSecurityException - in case of error
      • sha256

        public byte[] sha256​(byte[] in)
                      throws java.security.GeneralSecurityException
        Creates an SHA-256 message digest for the given input. This should be your best choice to verify signatures and certificates.
        Parameters:
        in - the input
        Returns:
        the SHA-256 message digest for the input
        Throws:
        java.security.GeneralSecurityException - in case of error
      • sha512

        public byte[] sha512​(byte[] in)
                      throws java.security.GeneralSecurityException
        Creates an SHA-512 message digest for the given input.
        Parameters:
        in - the input
        Returns:
        the SHA-256 message digest for the input
        Throws:
        java.security.GeneralSecurityException - in case of error
      • createHash

        public byte[] createHash​(java.lang.String algorithm,
                                 byte[] in)
                          throws java.security.GeneralSecurityException
        Creates an message digest of the given algorithm for the given input.
        Parameters:
        algorithm - the name of the digest algorithm to use
        in - the input
        Returns:
        the message digest for the input
        Throws:
        java.security.GeneralSecurityException - in case of error
      • createHash

        public byte[] createHash​(java.lang.String provider,
                                 java.lang.String algorithm,
                                 byte[] in)
                          throws java.security.GeneralSecurityException
        Creates an message digest of the given algorithm for the given input
        Parameters:
        provider - the provider to use
        algorithm - the name of the digest algorithm to use
        in - the input
        Returns:
        the message digest for the input
        Throws:
        java.security.GeneralSecurityException - in case of error
      • createHashWithKey

        public byte[] createHashWithKey​(java.lang.String provider,
                                        byte[] inputKey,
                                        byte[] in)
                                 throws java.security.GeneralSecurityException
        Creates an message digest of the given algorithm for the given input
        Parameters:
        provider - the provider to use
        inputKey - the key
        in - the input message
        Returns:
        the message digest
        Throws:
        java.security.GeneralSecurityException - in case of error
        UnsupportedEncodingException - in case of error