Apache Commons logo Commons Crypto? logo

User guide

Apache Commons Crypto is a cryptographic library optimized with AES-NI (Advanced Encryption Standard New Instructions). It provides Java API for both cipher level and Java stream level. Developers can use it to implement high performance AES encryption/decryption with the minimum code and effort. Please note that Apache Commons Crypto doesn't implement the cryptographic algorithm such as AES directly. It wraps to Openssl or JCE which implement the algorithms.

Interfaces Overview

Interfaces and classes used by the various implementation in the sub-packages.

random The interface for CryptoRandom.
cipher The interface of cryptographic cipher for encryption and decryption.
stream The interface wraps the underlying stream and it automatically encrypts the stream when data is written and decrypts the stream when data is read.

Usage

Prerequisites

Commons Crypto relies on standard JDK 1.7 (or above) and OpenSSL 1.0.1c (or above) for production deployment.

Using Commons Crypto in your Apache Maven build

To build with Apache Maven, add the dependencies listed below to your pom.xml file.

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-crypto</artifactId>
    <version>1.0.0</version>
</dependency>

Usage of Random API

CryptoRandom provides a cryptographically strong random number generators. The default implementation will use Intel® Digital Random Number Generator (DRNG) for accelerating the random generation.

RandomExample.java

Usage of Cipher API

Cipher provides an cryptographic interface for encryption and decryption. We provide two kind of implementations: JCE Cipher and Openssl Cipher. The JCE implementation uses JCE provider and the Openssl implementation uses Intel® AES New Instructions (Intel® AES NI).

Usage of Byte Array Encryption/Decryption
CipherByteArrayExample.java
Usage of ByteBuffer Encryption/Decryption
CipherByteBufferExample.java

Usage of Stream API

Stream provides the data encryption and decryption in stream manner. We provide CryptoInputStream, CTRCryptoInputStream, PositionedCryptoInputStream implementations for InputStream and CryptoOutputStream, CTRCryptoOutputStream implementations for OutputStream.

Usage of stream encryption/decryption
StreamExample.java