Class AESHelper
- java.lang.Object
-
- com.feedzai.commons.sql.abstraction.util.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 Summary
Constructors Constructor Description AESHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]decrypt(byte[] c, String key)Decrypts a byte[] encrypted byencrypt(java.lang.String, java.lang.String)method.static Stringdecrypt(String c, String key)Decrypts a string encrypted byencrypt(java.lang.String, java.lang.String)method.static byte[]decryptFile(String path, String key)Decrypts a file encrypted byencryptToFile(String, byte[], String)method.static Stringencrypt(byte[] c, String key)Encrypts a byte[].static Stringencrypt(String c, String key)Encrypts a string.static voidencryptToFile(String path, byte[] buf, String key)Encrypts the byte[] to a file.static byte[]readFile(String filePath)Reads a file.
-
-
-
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 String decrypt(String c, String key)
Decrypts a string encrypted byencrypt(java.lang.String, java.lang.String)method.- Parameters:
c- The encrypted HEX string.key- The key.- Returns:
- The decrypted string.
-
decrypt
public static byte[] decrypt(byte[] c, String key)Decrypts a byte[] encrypted byencrypt(java.lang.String, java.lang.String)method.- Parameters:
c- The encrypted HEX byte[].key- The key.- Returns:
- The decrypted string in a byte[].
-
decryptFile
public static byte[] decryptFile(String path, String key)
Decrypts a file encrypted byencryptToFile(String, byte[], String)method.- Parameters:
path- The file path to decrypt.key- The key.- Returns:
- A decrypted 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.
-
-