Package cn.dlysxx.www.common.crypto
Class AESCryptoUtil
java.lang.Object
cn.dlysxx.www.common.crypto.AESCryptoUtil
Class to encrypt/decrypt file or string in AES.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voiddecryptFile(String inputFilePath, String outputFilePath, String password) Decrypt file in AES.static byte[]decryptString(String encrypted, String password) Decrypt AES encrypted String.static voidencryptFile(String inputFilePath, String outputFilePath, String password) Encrypt file in AES.static byte[]encryptString(String plainText, String password) Encrypt plain text.
-
Constructor Details
-
AESCryptoUtil
public AESCryptoUtil()
-
-
Method Details
-
encryptString
public static byte[] encryptString(String plainText, String password) throws InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException Encrypt plain text. IMPORTANT: text should use UTF-8.- Parameters:
plainText- UTF-8 encoded textpassword- AES password- Returns:
- encrypted data byte array
- Throws:
InvalidKeyException- Invalid Key ExceptionInvalidAlgorithmParameterException- Invalid Algorithm Parameter ExceptionIllegalBlockSizeException- Illegal Block Size ExceptionBadPaddingException- Bad Padding Exception
-
decryptString
public static byte[] decryptString(String encrypted, String password) throws InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException Decrypt AES encrypted String. IMPORTANT: text should use UTF-8.- Parameters:
encrypted- encrypted String with UTF-8 encodedpassword- AES password- Returns:
- decrypted byte array
- Throws:
InvalidKeyException- Invalid Key ExceptionInvalidAlgorithmParameterException- Invalid Algorithm Parameter ExceptionIllegalBlockSizeException- Illegal Block Size ExceptionBadPaddingException- Bad Padding Exception
-
encryptFile
public static void encryptFile(String inputFilePath, String outputFilePath, String password) throws InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException, IOException Encrypt file in AES.- Parameters:
inputFilePath- input file pathoutputFilePath- encrypted file pathpassword- AES password- Throws:
InvalidKeyException- Invalid Key ExceptionInvalidAlgorithmParameterException- Invalid Algorithm Parameter ExceptionIllegalBlockSizeException- Illegal Block Size ExceptionBadPaddingException- Bad Padding ExceptionIOException- IOException
-
decryptFile
public static void decryptFile(String inputFilePath, String outputFilePath, String password) throws IOException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException Decrypt file in AES.- Parameters:
inputFilePath- encrypted file pathoutputFilePath- output decrypted file pathpassword- AES password- Throws:
IOException- IOExceptionInvalidKeyException- Invalid Key ExceptionInvalidAlgorithmParameterException- Invalid Algorithm Parameter ExceptionIllegalBlockSizeException- Illegal Block Size ExceptionBadPaddingException- Bad Padding Exception
-