Class EncryptionTool


  • public class EncryptionTool
    extends java.lang.Object
    Encryption toolbox
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String HMAC_SHA1
      Hmac-SHA1 algorithm name
      static java.lang.String HMAC_SHA256
      Hmac-SHA256 algorithm name
      static java.lang.String HMAC_SHA512
      Hmac-SHA5212 algorithm name
    • Constructor Summary

      Constructors 
      Constructor Description
      EncryptionTool()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] decrypt​(byte[] value, java.lang.String key)
      Decrypt byte array value
      static java.lang.String decrypt​(java.lang.String value, java.lang.String key)
      Decrypt string value
      static byte[] encrypt​(byte[] value, java.lang.String key)
      Encrypt byte array value to byte array
      static java.lang.String encrypt​(java.lang.String value, java.lang.String key)
      Encrypt string value to string
      static java.lang.String signHmac​(byte[] data, java.lang.String key, java.lang.String algo)
      Hmac signature
      static java.lang.String signHmacSHA1​(byte[] data, java.lang.String key)
      Hmac SHA1 signature
      static java.lang.String signHmacSHA1​(java.lang.String data, java.lang.String key)
      Hmac SHA1 signature
      static java.lang.String signHmacSHA256​(byte[] data, java.lang.String key)
      Hmac SHA256 signature
      static java.lang.String signHmacSHA256​(java.lang.String data, java.lang.String key)
      Hmac SHA256 signature
      static java.lang.String signHmacSHA512​(byte[] data, java.lang.String key)
      Hmac SHA512 signature
      static java.lang.String signHmacSHA512​(java.lang.String data, java.lang.String key)
      Hmac SHA512 signature
      static java.lang.String toHex​(byte[] data)
      To hexadecimal string
      static java.lang.String toHex​(java.lang.String data)
      To hexadecimal string
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • HMAC_SHA1

        public static final java.lang.String HMAC_SHA1
        Hmac-SHA1 algorithm name
        See Also:
        Constant Field Values
      • HMAC_SHA256

        public static final java.lang.String HMAC_SHA256
        Hmac-SHA256 algorithm name
        See Also:
        Constant Field Values
      • HMAC_SHA512

        public static final java.lang.String HMAC_SHA512
        Hmac-SHA5212 algorithm name
        See Also:
        Constant Field Values
    • Constructor Detail

      • EncryptionTool

        public EncryptionTool()
    • Method Detail

      • encrypt

        public static byte[] encrypt​(byte[] value,
                                     java.lang.String key)
                              throws java.lang.Exception
        Encrypt byte array value to byte array
        Parameters:
        value - Value
        key - Encryption key
        Throws:
        java.lang.Exception
      • encrypt

        public static java.lang.String encrypt​(java.lang.String value,
                                               java.lang.String key)
                                        throws java.lang.Exception
        Encrypt string value to string
        Parameters:
        value - Value
        key - Encryption key
        Throws:
        java.lang.Exception
      • decrypt

        public static byte[] decrypt​(byte[] value,
                                     java.lang.String key)
                              throws java.lang.Exception
        Decrypt byte array value
        Parameters:
        value - Value
        key - Encryption key
        Throws:
        java.lang.Exception
      • decrypt

        public static java.lang.String decrypt​(java.lang.String value,
                                               java.lang.String key)
                                        throws java.lang.Exception
        Decrypt string value
        Parameters:
        value - Value
        key - Encryption key
        Throws:
        java.lang.Exception
      • toHex

        public static java.lang.String toHex​(java.lang.String data)
        To hexadecimal string
        Parameters:
        data - String data
        Returns:
        Hexadecimal string
      • toHex

        public static java.lang.String toHex​(byte[] data)
        To hexadecimal string
        Parameters:
        data - Byte arry data
        Returns:
        Hexadecimal string
      • signHmacSHA1

        public static java.lang.String signHmacSHA1​(java.lang.String data,
                                                    java.lang.String key)
                                             throws java.lang.Exception
        Hmac SHA1 signature
        Parameters:
        data - String data
        key - Key
        Returns:
        Hexadecimal string of signature
        Throws:
        java.lang.Exception
      • signHmacSHA1

        public static java.lang.String signHmacSHA1​(byte[] data,
                                                    java.lang.String key)
                                             throws java.lang.Exception
        Hmac SHA1 signature
        Parameters:
        data - Byte array data
        key - Key
        Returns:
        Hexadecimal string of signature
        Throws:
        java.lang.Exception
      • signHmacSHA256

        public static java.lang.String signHmacSHA256​(java.lang.String data,
                                                      java.lang.String key)
                                               throws java.lang.Exception
        Hmac SHA256 signature
        Parameters:
        data - String data
        key - Key
        Returns:
        Hexadecimal string of signature
        Throws:
        java.lang.Exception
      • signHmacSHA256

        public static java.lang.String signHmacSHA256​(byte[] data,
                                                      java.lang.String key)
                                               throws java.lang.Exception
        Hmac SHA256 signature
        Parameters:
        data - Byte array data
        key - Key
        Returns:
        Hexadecimal string of signature
        Throws:
        java.lang.Exception
      • signHmacSHA512

        public static java.lang.String signHmacSHA512​(java.lang.String data,
                                                      java.lang.String key)
                                               throws java.lang.Exception
        Hmac SHA512 signature
        Parameters:
        data - String data
        key - Key
        Returns:
        Hexadecimal string of signature
        Throws:
        java.lang.Exception
      • signHmacSHA512

        public static java.lang.String signHmacSHA512​(byte[] data,
                                                      java.lang.String key)
                                               throws java.lang.Exception
        Hmac SHA512 signature
        Parameters:
        data - Byte array data
        key - Key
        Returns:
        Hexadecimal string of signature
        Throws:
        java.lang.Exception
      • signHmac

        public static java.lang.String signHmac​(byte[] data,
                                                java.lang.String key,
                                                java.lang.String algo)
                                         throws java.lang.Exception
        Hmac signature
        Parameters:
        data - Byte array data
        key - Key
        algo - Alogorithm (one of HMAC*)
        Returns:
        Hexadecimal string of signature
        Throws:
        java.lang.Exception