TakahikoKawasaki / nv-cipher

Cipher tools.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nv-cipher

Overview

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.

License

Apache License, Version 2.0

Download

git clone https://github.com/TakahikoKawasaki/nv-cipher.git

JavaDoc

nv-cipher JavaDoc

Example

// 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);

Maven

<dependency>
    <groupId>com.neovisionaries</groupId>
    <artifactId>nv-cipher</artifactId>
    <version>1.4</version>
</dependency>

See Also

Author

Takahiko Kawasaki @ Authlete, Inc.

About

Cipher tools.

License:Apache License 2.0


Languages

Language:Java 100.0%