Class CryptUtil
- java.lang.Object
-
- com.github.toolarium.security.util.CryptUtil
-
public final class CryptUtil extends java.lang.ObjectThis is a simple util class for initialisation or checks.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringALGORITHM_AESRepresents the AES algorithm as string
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description javax.crypto.spec.SecretKeySpeccreateSecretKeySpec(byte[] key, java.lang.String algorithm)Create a SecretKeySpecjavax.crypto.spec.SecretKeySpeccreateSecretKeySpec(java.lang.String keyString)Create a SecretKeySpecjava.lang.StringgetAlgorithmMessage(java.lang.String provider, java.lang.String algorithm)Prepare algorithm messagejavax.crypto.CiphergetCipher(java.lang.String algorithm)Get cipherjavax.crypto.CiphergetCipher(java.lang.String provider, java.lang.String algorithm)Get cipherstatic CryptUtilgetInstance()Get the instanceintgetMaxAllowedKeyLength(java.lang.String algorithm)Prepare algorithm max key lengthbooleanisStrongEncryptionEnabled()Check if strong cryption is enabled or not
-
-
-
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.GeneralSecurityExceptionGet 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.GeneralSecurityExceptionGet cipher- Parameters:
provider- the provideralgorithm- 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 provideralgorithm- 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.NoSuchAlgorithmExceptionCreate a SecretKeySpec- Parameters:
keyString- the key as string- Returns:
- the SecretKeySpec
- Throws:
java.io.UnsupportedEncodingException- In case of unsupported encodingjava.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 keyalgorithm- the algorithm- Returns:
- the SecretKeySpec
-
-