Class CryptoHelper


  • public class CryptoHelper
    extends java.lang.Object
    Since:
    2018-02-24
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String SEC_PROV  
    • Constructor Summary

      Constructors 
      Constructor Description
      CryptoHelper()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] crcHash​(byte[] input)
      Performs CRC32 on an input byte array using the CrcStandard.Crc32Bit parameters
      static byte[] generateRandomBlock​(int size)
      Generate an array of random bytes given the input length
      static byte[] symmetricDecrypt​(byte[] input, byte[] key)
      Decrypts using AES/CBC/PKCS7 with an input byte array and key, using the random IV prepended using AES/ECB/None
      static byte[] symmetricDecrypt​(byte[] input, byte[] key, Passable<byte[]> iv)
      Decrypts using AES/CBC/PKCS7 with an input byte array and key, using the random IV prepended using AES/ECB/None
      static byte[] symmetricDecryptHMACIV​(byte[] input, byte[] key, byte[] hmacSecret)
      Decrypts using AES/CBC/PKCS7 with an input byte array and key, using the IV (comprised of random bytes and the HMAC-SHA1 of the random bytes and plaintext) prepended using AES/ECB/None
      static byte[] symmetricEncrypt​(byte[] input, byte[] key)
      Performs an encryption using AES/CBC/PKCS7 with an input byte array and key, with a random IV prepended using AES/ECB/None
      static byte[] symmetricEncryptWithHMACIV​(byte[] input, byte[] key, byte[] hmacSecret)
      Performs an encryption using AES/CBC/PKCS7 with an input byte array and key, with a IV (comprised of random bytes and the HMAC-SHA1 of the random bytes and plaintext) prepended using AES/ECB/None
      static byte[] symmetricEncryptWithIV​(byte[] input, byte[] key, byte[] iv)
      Performs an encryption using AES/CBC/PKCS7 with an input byte array and key, with a random IV prepended using AES/ECB/None
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • SEC_PROV

        public static final java.lang.String SEC_PROV
    • Constructor Detail

      • CryptoHelper

        public CryptoHelper()
    • Method Detail

      • generateRandomBlock

        public static byte[] generateRandomBlock​(int size)
        Generate an array of random bytes given the input length
        Parameters:
        size - the size of the block to generate
        Returns:
        the generated block
      • crcHash

        public static byte[] crcHash​(byte[] input)
        Performs CRC32 on an input byte array using the CrcStandard.Crc32Bit parameters
        Parameters:
        input - array to hash
        Returns:
        the hashed result
      • symmetricDecrypt

        public static byte[] symmetricDecrypt​(byte[] input,
                                              byte[] key)
                                       throws CryptoException
        Decrypts using AES/CBC/PKCS7 with an input byte array and key, using the random IV prepended using AES/ECB/None
        Parameters:
        input - array to decrypt
        key - encryption key
        Returns:
        decrypted message
        Throws:
        CryptoException - deception while encrypting
      • symmetricDecrypt

        public static byte[] symmetricDecrypt​(byte[] input,
                                              byte[] key,
                                              Passable<byte[]> iv)
                                       throws CryptoException
        Decrypts using AES/CBC/PKCS7 with an input byte array and key, using the random IV prepended using AES/ECB/None
        Parameters:
        input - array to decrypt
        key - encryption key
        iv - the random IV
        Returns:
        decrypted message
        Throws:
        CryptoException - deception while encrypting
      • symmetricEncryptWithIV

        public static byte[] symmetricEncryptWithIV​(byte[] input,
                                                    byte[] key,
                                                    byte[] iv)
                                             throws CryptoException
        Performs an encryption using AES/CBC/PKCS7 with an input byte array and key, with a random IV prepended using AES/ECB/None
        Parameters:
        input - array to encrypt
        key - encryption key
        iv - the random IV
        Returns:
        encrypted message
        Throws:
        CryptoException - exception while encrypting
      • symmetricEncrypt

        public static byte[] symmetricEncrypt​(byte[] input,
                                              byte[] key)
                                       throws CryptoException
        Performs an encryption using AES/CBC/PKCS7 with an input byte array and key, with a random IV prepended using AES/ECB/None
        Parameters:
        input - array to encrypt
        key - encryption key
        Returns:
        encrypted message
        Throws:
        CryptoException - exception while encrypting
      • symmetricDecryptHMACIV

        public static byte[] symmetricDecryptHMACIV​(byte[] input,
                                                    byte[] key,
                                                    byte[] hmacSecret)
                                             throws CryptoException
        Decrypts using AES/CBC/PKCS7 with an input byte array and key, using the IV (comprised of random bytes and the HMAC-SHA1 of the random bytes and plaintext) prepended using AES/ECB/None
        Parameters:
        input - array to decrypt
        key - encryption key
        hmacSecret - the IV
        Returns:
        decrypted message
        Throws:
        CryptoException - exception while decrypting
      • symmetricEncryptWithHMACIV

        public static byte[] symmetricEncryptWithHMACIV​(byte[] input,
                                                        byte[] key,
                                                        byte[] hmacSecret)
                                                 throws CryptoException
        Performs an encryption using AES/CBC/PKCS7 with an input byte array and key, with a IV (comprised of random bytes and the HMAC-SHA1 of the random bytes and plaintext) prepended using AES/ECB/None
        Parameters:
        input - array to encrypt
        key - encryption key
        hmacSecret - the IV
        Returns:
        encrypted message
        Throws:
        CryptoException - exception while encrypting