Class CryptoHelper


  • public class CryptoHelper
    extends Object
    • Constructor Detail

      • CryptoHelper

        public CryptoHelper()
    • 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 input
        digestAlgorithm - DigestAlgorithmType enumeration MD2 | MD5 | SHA-1 | SHA-256 | SHA-384 | SHA-512
        secretKeyAlgorithm - 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 encrypt
        cipher - the cipher
        Returns:
        the string
      • createDefaultCipher

        public static Cipher createDefaultCipher​(String secretKey,
                                                 boolean encryptMode)
                                          throws Exception
        Creates the default cipher.
        Parameters:
        secretKey - the secret key
        encryptMode - 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/decrypting
        cipherAlgorithm - AES | AES/CBC/NoPadding | AES/ECB/PKCS5PADDING | etc. There must be an available provider
        encryptMode - 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 key
        encryptMode - 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 encrypt
        digestInput - 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 encrypt
        secretKey - the secret key
        Returns:
        the string
      • decrypt

        public static String decrypt​(String strToDecrypt,
                                     Cipher cipher)
        Decrypt.
        Parameters:
        strToDecrypt - the str to decrypt
        cipher - the cipher
        Returns:
        the string
      • decrypt

        public static String decrypt​(String utf8StrToDecrypt,
                                     SecretKeySpec secretspec)
        Decrypt.
        Parameters:
        utf8StrToDecrypt - the utf 8 str to decrypt
        secretspec - the secretspec
        Returns:
        the string
      • decrypt

        public static String decrypt​(String value,
                                     String secretKey)
        Decrypt.
        Parameters:
        value - the value
        secretKey - the secret key
        Returns:
        the string