Class AES
java.lang.Object
net.ME1312.SubData.Client.Encryption.AES
- All Implemented Interfaces:
Cipher
A class to perform password-based AES encryption and decryption in CBC mode.
128, 192, and 256-bit encryption are supported, provided that the latter two
are permitted by the Java runtime's jurisdiction policy files.
The public interface for this class consists of the static methods
The public interface for this class consists of the static methods
encrypt(int, java.lang.String, java.io.InputStream, java.io.OutputStream)
and decrypt(java.lang.String, java.io.InputStream, java.io.OutputStream)
, which encrypt and decrypt arbitrary
streams of data, respectively.- Author:
- [email protected]
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Thrown if an attempt is made to decrypt an invalid AES stream.static class
Thrown if an attempt is made to encrypt a stream with an invalid AES key length.static class
Thrown if an attempt is made to decrypt a stream with an incorrect password.static class
Thrown if 192- or 256-bit AES encryption or decryption is attempted, but not available on the particular Java platform. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
decrypt
(String password, InputStream input, OutputStream output) Decrypts a stream of data that was encrypted byencrypt(int, java.lang.String, java.io.InputStream, java.io.OutputStream)
.void
decrypt
(DataClient client, InputStream in, OutputStream out) Decrypt Datastatic void
encrypt
(int keyLength, String password, InputStream input, OutputStream output) Encrypts a stream of data.void
encrypt
(DataClient client, InputStream in, OutputStream out) Encrypt DatagetName()
Get the name of this Cipher
-
Constructor Details
-
AES
Initialize AES Cipher- Parameters:
keyLength
- 128, 192, or 256 bit modekey
- Password
-
-
Method Details
-
encrypt
public static void encrypt(int keyLength, String password, InputStream input, OutputStream output) throws AES.InvalidKeyLengthException, AES.StrongEncryptionNotAvailableException, IOException Encrypts a stream of data. The encrypted stream consists of a header followed by the raw AES data. The header is broken down as follows:
- keyLength: AES key length in bytes (valid for 16, 24, 32) (1 byte)
- salt: pseudorandom salt used to derive keys from password (16 bytes)
- authentication key (derived from password and salt, used to check validity of password upon decryption) (8 bytes)
- IV: pseudorandom AES initialization vector (16 bytes)
- Parameters:
keyLength
- key length to use for AES encryption (must be 128, 192, or 256)password
- password to use for encryptioninput
- an arbitrary byte stream to encryptoutput
- stream to which encrypted data will be written- Throws:
AES.InvalidKeyLengthException
- if keyLength is not 128, 192, or 256AES.StrongEncryptionNotAvailableException
- if keyLength is 192 or 256, but the Java runtime's jurisdiction policy files do not allow 192- or 256-bit encryptionIOException
-
encrypt
Description copied from interface:Cipher
Encrypt Data -
getName
Description copied from interface:Cipher
Get the name of this Cipher -
decrypt
public static int decrypt(String password, InputStream input, OutputStream output) throws AES.InvalidPasswordException, AES.InvalidAESStreamException, IOException, AES.StrongEncryptionNotAvailableException Decrypts a stream of data that was encrypted byencrypt(int, java.lang.String, java.io.InputStream, java.io.OutputStream)
.- Parameters:
password
- the password used to encrypt/decrypt the streaminput
- stream of encrypted data to be decryptedoutput
- stream to which decrypted data will be written- Returns:
- the key length for the decrypted stream (128, 192, or 256)
- Throws:
AES.InvalidPasswordException
- if the given password was not used to encrypt the dataAES.InvalidAESStreamException
- if the given input stream is not a valid AES-encrypted streamAES.StrongEncryptionNotAvailableException
- if the stream is 192 or 256-bit encrypted, and the Java runtime's jurisdiction policy files do not allow for AES-192 or 256IOException
-
decrypt
Description copied from interface:Cipher
Decrypt Data
-