Class CryptUtil


  • public final class CryptUtil
    extends java.lang.Object
    This is a simple util class for initialisation or checks.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String ALGORITHM_AES
      Represents the AES algorithm as string
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      javax.crypto.spec.SecretKeySpec createSecretKeySpec​(byte[] key, java.lang.String algorithm)
      Create a SecretKeySpec
      javax.crypto.spec.SecretKeySpec createSecretKeySpec​(java.lang.String keyString)
      Create a SecretKeySpec
      java.lang.String getAlgorithmMessage​(java.lang.String provider, java.lang.String algorithm)
      Prepare algorithm message
      javax.crypto.Cipher getCipher​(java.lang.String algorithm)
      Get cipher
      javax.crypto.Cipher getCipher​(java.lang.String provider, java.lang.String algorithm)
      Get cipher
      static CryptUtil getInstance()
      Get the instance
      int getMaxAllowedKeyLength​(java.lang.String algorithm)
      Prepare algorithm max key length
      boolean isStrongEncryptionEnabled()
      Check if strong cryption is enabled or not
      • Methods inherited from class java.lang.Object

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

      • ALGORITHM_AES

        public static final java.lang.String ALGORITHM_AES
        Represents the AES algorithm as string
        See Also:
        Constant Field Values
    • Method Detail

      • getInstance

        public static CryptUtil getInstance()
        Get the instance
        Returns:
        the instance
      • isStrongEncryptionEnabled

        public boolean isStrongEncryptionEnabled()
        Check if strong cryption is enabled or not
        Returns:
        true if strong cryption is enabled; otherwise false
      • getCipher

        public javax.crypto.Cipher getCipher​(java.lang.String algorithm)
                                      throws java.security.GeneralSecurityException
        Get cipher
        Parameters:
        algorithm - the algorithm
        Returns:
        the cipher object
        Throws:
        java.security.GeneralSecurityException - in case of error
      • getCipher

        public javax.crypto.Cipher getCipher​(java.lang.String provider,
                                             java.lang.String algorithm)
                                      throws java.security.GeneralSecurityException
        Get cipher
        Parameters:
        provider - the provider
        algorithm - the algorithm
        Returns:
        the cipher object
        Throws:
        java.security.GeneralSecurityException - in case of error
      • getAlgorithmMessage

        public java.lang.String getAlgorithmMessage​(java.lang.String provider,
                                                    java.lang.String algorithm)
        Prepare algorithm message
        Parameters:
        provider - the provider
        algorithm - the algorithm
        Returns:
        the prepared message
      • getMaxAllowedKeyLength

        public int getMaxAllowedKeyLength​(java.lang.String algorithm)
        Prepare algorithm max key length
        Parameters:
        algorithm - the algorithm
        Returns:
        the prepared message
      • createSecretKeySpec

        public javax.crypto.spec.SecretKeySpec createSecretKeySpec​(java.lang.String keyString)
                                                            throws java.io.UnsupportedEncodingException,
                                                                   java.security.NoSuchAlgorithmException
        Create a SecretKeySpec
        Parameters:
        keyString - the key as string
        Returns:
        the SecretKeySpec
        Throws:
        java.io.UnsupportedEncodingException - In case of unsupported encoding
        java.security.NoSuchAlgorithmException - In case of invalid algorithm
      • createSecretKeySpec

        public javax.crypto.spec.SecretKeySpec createSecretKeySpec​(byte[] key,
                                                                   java.lang.String algorithm)
        Create a SecretKeySpec
        Parameters:
        key - the initial key
        algorithm - the algorithm
        Returns:
        the SecretKeySpec