Class CryptUtil

java.lang.Object
com.github.toolarium.security.util.CryptUtil

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

  • Method Details

    • 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 Cipher getCipher(String algorithm) throws GeneralSecurityException
      Get cipher
      Parameters:
      algorithm - the algorithm
      Returns:
      the cipher object
      Throws:
      GeneralSecurityException - in case of error
    • getCipher

      public Cipher getCipher(String provider, String algorithm) throws GeneralSecurityException
      Get cipher
      Parameters:
      provider - the provider
      algorithm - the algorithm
      Returns:
      the cipher object
      Throws:
      GeneralSecurityException - in case of error
    • getAlgorithmMessage

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

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

      public SecretKeySpec createSecretKeySpec(String keyString) throws UnsupportedEncodingException, NoSuchAlgorithmException
      Create a SecretKeySpec
      Parameters:
      keyString - the key as string
      Returns:
      the SecretKeySpec
      Throws:
      UnsupportedEncodingException - In case of unsupported encoding
      NoSuchAlgorithmException - In case of invalid algorithm
    • createSecretKeySpec

      public SecretKeySpec createSecretKeySpec(byte[] key, String algorithm)
      Create a SecretKeySpec
      Parameters:
      key - the initial key
      algorithm - the algorithm
      Returns:
      the SecretKeySpec