public interface AES
This interface provides methods for AES encryption and decryption.
-
Method Summary
Modifier and TypeMethodDescriptionstatic AESReturn AES instance with specified key generation function.static AESaes256()Return AES instance with default 256-bit key generation function.byte[]Decrypt byte array.byte[]decrypt(InputStream in, String password) Decrypt input stream.decryptString(byte[] bytes, String password) Decrypt stringbyte[]Encrypt byte array.voidencrypt(byte[] src, String password, OutputStream out) Encrypt bytes and write the result into the stream.default byte[]Encrypt string.default voidencrypt(String str, String password, OutputStream out) Encrypt string and write the result into the stream.static byte[]generate256key(String password) Default 256-bit key generator.getInputStream(InputStream in, String password) getOutputStream(OutputStream out, String password)
-
Method Details
-
encrypt
Encrypt string.- Parameters:
str- stringpassword- password- Returns:
- encrypted bytes
-
encrypt
Encrypt byte array.- Parameters:
src- byte arraypassword- password- Returns:
- encrypted bytes
-
encrypt
Encrypt bytes and write the result into the stream.- Parameters:
src- bytes to encryptpassword- passwordout- stream- Throws:
IOException- in case of error
-
encrypt
Encrypt string and write the result into the stream.- Parameters:
str- string to encryptpassword- passwordout- stream- Throws:
IOException- in case of error
-
decrypt
Decrypt byte array.- Parameters:
bytes- bytes to decryptpassword- password to decrypt- Returns:
- decrypted bytes
-
decryptString
Decrypt string- Parameters:
bytes- bytes to decryptpassword- password to decrypt- Returns:
- decrypted bytes
-
decrypt
Decrypt input stream. Stream must be obtained viagetInputStream(InputStream, String).- Parameters:
in- stream to decryptpassword- password to decrypt- Returns:
- decrypted bytes
- Throws:
IOException- in case of error
-
getInputStream
- Throws:
IOException
-
getOutputStream
- Throws:
IOException
-
generate256key
Default 256-bit key generator. This implementation uses SHA-256 message digest algorithm.- Parameters:
password- password string- Returns:
- key bytes
-
aes
Return AES instance with specified key generation function.- Parameters:
keyGen- key generation function- Returns:
- in case of error
-
aes256
Return AES instance with default 256-bit key generation function. Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files for the appropriate JRE must be installed to use 256-bit keys.- Returns:
- AES instance
-