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 intDEFAULT_AES_SECRETKEY_LENstatic StringDEFAULT_CIPHER_MODEstatic DigestAlgorithmTypeDEFAULT_DIGEST_ALGORITHMstatic StringDEFAULT_SECRETKEY_ALGORITHM
-
Constructor Summary
Constructors Constructor Description CryptoHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static CiphercreateCipher(SecretKeySpec secretKey, String cipherAlgorithm, boolean encryptMode)Creates the cipher.static CiphercreateDefaultCipher(String secretKey, boolean encryptMode)Creates the default cipher.static CiphercreateDefaultCipher(SecretKeySpec secretKey, boolean encryptMode)Creates the default cipher.static SecretKeySpeccreateSecretKey(String utf8DigestInput, DigestAlgorithmType digestAlgorithm, String secretKeyAlgorithm)Creates the secret key.static SecretKeySpeccreateSHA512AESSecretKey(String digestInput)Creates the SHA 512 AES secret key.static Stringdecrypt(String value, String secretKey)Decrypt.static Stringdecrypt(String strToDecrypt, Cipher cipher)Decrypt.static Stringdecrypt(String utf8StrToDecrypt, SecretKeySpec secretspec)Decrypt.static Stringencrypt(String utf8StrToEncrypt, Cipher cipher)Encrypt.static StringencryptSHA512AESPKCS5Pad(String utf8StrToEncrypt, String digestInput)Encrypt SHA 512 AESPKCS 5 pad.static StringencryptSHA512AESPKCS5Pad(String utf8StrToEncrypt, SecretKeySpec secretKey)Encrypt SHA 512 AESPKCS 5 pad.
-
-
-
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 provderencryptMode- 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
-
encryptSHA512AESPKCS5Pad
public static String encryptSHA512AESPKCS5Pad(String utf8StrToEncrypt, String digestInput)
Encrypt SHA 512 AESPKCS 5 pad.- Parameters:
utf8StrToEncrypt- the utf 8 str to encryptdigestInput- the digest input- Returns:
- the string
-
encryptSHA512AESPKCS5Pad
public static String encryptSHA512AESPKCS5Pad(String utf8StrToEncrypt, SecretKeySpec secretKey)
Encrypt SHA 512 AESPKCS 5 pad.- 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
-
-