Java AES encryption library
Alice is a Java AES/DES encryption library for working with byte arrays, files, and streams. Various key lengths, block modes, padding schemes, key deriviation functions, and Message Authentication Codes (MAC) are available. See the javadoc for more information.
Alice provides an easy wrapper around the javax.crypto cipher suite for symmetric key encryption. if a MAC algorithm is selected, additional Authenticated Encryption is performed using an encrypt-then-mac scheme.
Algorithms
Modes
Padding
Key Lengths (in bits)
Password Based Key Derivation Functions (PBKDF)
MAC Algorithm (Authenticated Encryption)
IV Length
GCM Tag Length (in bits)
Iterations (used when the PBKDF = PBKDF2WithHmacSHA{Length})
The easist way is to use jitpack
// Initialize an Alice instance with defaults:
// Cipher = AES/256/CTR/NoPadding
// Key Derivation = PBKDF2WithHmacSHA512/Iterations(10000)
// MAC = HmacSHA512
Alice alice = new Alice(new AliceContextBuilder().build());
AliceContext aliceContext = new AliceContextBuilder()
.setAlgorithm(AliceContext.Algorithm.AES)
.setMode(AliceContext.Mode.CBC) // or AliceContext.Mode.CTR
.setIvLength(16)
.build()
AliceContext aliceContext = new AliceContextBuilder()
.setAlgorithm(AliceContext.Algorithm.AES)
.setMode(AliceContext.Mode.GCM)
.setIvLength(ivLength) // e.g. 12
.setGcmTagLength(AliceContext.GcmTagLength.BITS_128)
.build()
AliceContext aliceContext = new AliceContextBuilder()
.setAlgorithm(AliceContext.Algorithm.DES)
.setMode(AliceContext.Mode.CBC) // or AliceContext.Mode.CTR
.setIvLength(8)
.build()
AliceContext aliceContext = new AliceContextBuilder()
.setAlgorithm(AliceContext.Algorithm.DESede)
.setMode(AliceContext.Mode.CBC) // or AliceContext.Mode.CTR
.setIvLength(8)
.build()
After you've created an Alice instance with the desired context you can encrypt/decrypt byte arrays and files as shown. See the unit tests for more detailed usage and options.
byte[] encryptedBytes = alice.encrypt(input, password);
byte[] decryptedBytes = alice.decrypt(encryptedBytes, password);
alice.encrypt(inputFile, encryptedFile, password);
alice.decrypt(encryptedFile, decryptedFile, password);
Note: Streaming encryption does not support authenticated encryption. You must set the mac algorithm to AliceContext.MacAlgorithm.NONE
alice.encrypt(inputStream, encryptedStream, password);
alice.decrypt(encryptedStream, decryptedStream, password);