Package org.hpccsystems.commons.utils
Class CryptoHelper
- java.lang.Object
-
- org.hpccsystems.commons.utils.CryptoHelper
-
public class CryptoHelper extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_AES_SECRETKEY_LEN
static String
DEFAULT_CIPHER_MODE
static DigestAlgorithmType
DEFAULT_DIGEST_ALGORITHM
static String
DEFAULT_SECRETKEY_ALGORITHM
-
Constructor Summary
Constructors Constructor Description CryptoHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static Cipher
createCipher(SecretKeySpec secretKey, String cipherAlgorithm, boolean encryptMode)
Creates the cipher.static Cipher
createDefaultCipher(String secretKey, boolean encryptMode)
Creates the default cipher.static Cipher
createDefaultCipher(SecretKeySpec secretKey, boolean encryptMode)
Creates the default cipher.static SecretKeySpec
createSecretKey(String utf8DigestInput, DigestAlgorithmType digestAlgorithm, String secretKeyAlgorithm)
Creates the secret key.static SecretKeySpec
createSHA512AESSecretKey(String digestInput)
Creates the SHA 512 AES secret key.static String
decrypt(String value, String secretKey)
Decrypt.static String
decrypt(String strToDecrypt, Cipher cipher)
Decrypt.static String
decrypt(String utf8StrToDecrypt, SecretKeySpec secretspec)
Decrypt.static String
encrypt(String utf8StrToEncrypt, Cipher cipher)
Encrypt.static String
encryptSHA512AES(String utf8StrToEncrypt, String digestInput)
Deprecated.static String
encryptSHA512AES(String utf8StrToEncrypt, SecretKeySpec secretKey)
Deprecated.
-
-
-
Field Detail
-
DEFAULT_DIGEST_ALGORITHM
public static final DigestAlgorithmType DEFAULT_DIGEST_ALGORITHM
-
DEFAULT_SECRETKEY_ALGORITHM
public static final String DEFAULT_SECRETKEY_ALGORITHM
- See Also:
- Constant Field Values
-
DEFAULT_AES_SECRETKEY_LEN
public static final int DEFAULT_AES_SECRETKEY_LEN
- See Also:
- Constant Field Values
-
DEFAULT_CIPHER_MODE
public static final String DEFAULT_CIPHER_MODE
- See Also:
- Constant Field Values
-
-
Method Detail
-
createSHA512AESSecretKey
public static SecretKeySpec createSHA512AESSecretKey(String digestInput)
Creates the SHA 512 AES secret key.- Parameters:
digestInput
- the digest input- Returns:
- the secret key spec
-
createSecretKey
public static SecretKeySpec createSecretKey(String utf8DigestInput, DigestAlgorithmType digestAlgorithm, String secretKeyAlgorithm)
Creates the secret key.- Parameters:
utf8DigestInput
- the utf 8 digest inputdigestAlgorithm
- DigestAlgorithmType enumeration MD2 | MD5 | SHA-1 | SHA-256 | SHA-384 | SHA-512secretKeyAlgorithm
- the secret key algorithm- Returns:
- the secret key spec
-
encrypt
public static String encrypt(String utf8StrToEncrypt, Cipher cipher)
Encrypt.- Parameters:
utf8StrToEncrypt
- the utf 8 str to encryptcipher
- the cipher- Returns:
- the string
-
createDefaultCipher
public static Cipher createDefaultCipher(String secretKey, boolean encryptMode) throws Exception
Creates the default cipher.- Parameters:
secretKey
- the secret keyencryptMode
- the encrypt mode- Returns:
- the cipher
- Throws:
Exception
- the exception
-
createCipher
public static Cipher createCipher(SecretKeySpec secretKey, String cipherAlgorithm, boolean encryptMode) throws Exception
Creates the cipher.- Parameters:
secretKey
- The key to use for encrypting/decryptingcipherAlgorithm
- AES | AES/CBC/NoPadding | AES/ECB/PKCS5PADDING | etc. There must be an available providerencryptMode
- true=encrypt, false=decrypt- Returns:
- the cipher
- Throws:
Exception
- the exception
-
createDefaultCipher
public static Cipher createDefaultCipher(SecretKeySpec secretKey, boolean encryptMode) throws Exception
Creates the default cipher.- Parameters:
secretKey
- the secret keyencryptMode
- the encrypt mode- Returns:
- the cipher
- Throws:
Exception
- the exception
-
encryptSHA512AES
public static String encryptSHA512AES(String utf8StrToEncrypt, String digestInput)
Deprecated.Encrypt SHA 512 AES. Replaces public static String encryptSHA512AESPKCS5Pad(String utf8StrToEncrypt, String digestInput)- Parameters:
utf8StrToEncrypt
- the utf 8 str to encryptdigestInput
- the digest input- Returns:
- the string
-
encryptSHA512AES
public static String encryptSHA512AES(String utf8StrToEncrypt, SecretKeySpec secretKey)
Deprecated.Encrypt SHA 512 AES. Replaces public static String encryptSHA512AESPKCS5Pad(String utf8StrToEncrypt, SecretKeySpec secretKey)- Parameters:
utf8StrToEncrypt
- the utf 8 str to encryptsecretKey
- the secret key- Returns:
- the string
-
decrypt
public static String decrypt(String strToDecrypt, Cipher cipher)
Decrypt.- Parameters:
strToDecrypt
- the str to decryptcipher
- the cipher- Returns:
- the string
-
decrypt
public static String decrypt(String utf8StrToDecrypt, SecretKeySpec secretspec)
Decrypt.- Parameters:
utf8StrToDecrypt
- the utf 8 str to decryptsecretspec
- the secretspec- Returns:
- the string
-
-