Class AESHelper


  • public final class AESHelper
    extends Object
    Class to provide encryption and decryption using AES algorithm.
    Since:
    2.0.0
    Author:
    Rui Vilao (rui.vilao@feedzai.com)
    • Constructor Detail

      • AESHelper

        public AESHelper()
    • Method Detail

      • encrypt

        public static String encrypt​(String c,
                                     String key)
        Encrypts a string.
        Parameters:
        c - The string to encrypt.
        Returns:
        The encrypted string in HEX.
      • encrypt

        public static String encrypt​(byte[] c,
                                     String key)
        Encrypts a byte[].
        Parameters:
        c - The byte[] to encrypt.
        key - The key.
        Returns:
        The encrypted array as a HEX string.
      • decrypt

        public static byte[] decrypt​(byte[] c,
                                     String key)
        Decrypts a byte[] encrypted by encrypt(java.lang.String, java.lang.String) method.
        Parameters:
        c - The encrypted HEX byte[].
        key - The key.
        Returns:
        The decrypted string in a byte[].
      • encryptToFile

        public static void encryptToFile​(String path,
                                         byte[] buf,
                                         String key)
        Encrypts the byte[] to a file.
        Parameters:
        path - The destination path.
        buf - The buffer.
        key - The key.
      • readFile

        public static byte[] readFile​(String filePath)
                               throws IOException
        Reads a file.
        Parameters:
        filePath - The file path.
        Returns:
        a byte[] The file data.
        Throws:
        IOException - if an error occurs reading the file or if the file does not exists.