Cipher with encoder/decoder. BinaryEncoder and BinaryDecoder of Apache Commons Codec such as Base64, Hex and BinaryCodec can be used.
As a subclass of CodecCipher, AESCipher is contained which is dedicated to AES.
Apache License, Version 2.0
git clone https://github.com/TakahikoKawasaki/nv-cipher.git
// Create a cipher with a secret key.
AESCipher cipher = new AESCipher().setKey("secret key", "initial vector");
// Encryption & decryption.
// 'plaintext' and 'decrypted' have the same value.
String plaintext = "plain text";
String encrypted = cipher.encrypt(plaintext);
String decrypted = cipher.decrypt(encrypted);
// In the above example, 'encrypted' is encoded by Base64 (default).
// If you want to change the format, use setCoder method.
// For example, to change the format to hexadecimal:
Hex hex = new org.apache.commons.codec.binary.Hex();
cipher.setCoder(hex);
// Binary representation (only "0"s and "1"s) also can be used.
BinaryCodec binary = new org.apache.commons.codec.BinaryCodec();
cipher.setCoder(binary);
// Coder can be specified as a constructor parameter.
cipher = new AESCipher(hex);
// If you want, an encoder and a decoder can be set separately.
cipher.setEncoder(hex);
cipher.setDecoder(hex);
<dependency>
<groupId>com.neovisionaries</groupId>
<artifactId>nv-cipher</artifactId>
<version>1.4</version>
</dependency>
Takahiko Kawasaki @ Authlete, Inc.