Menu

Home

Michael Bock

Code sample file encryption

public static void main(String[] args) throws IOException {
    FileInputStream plainInput = new FileInputStream(args[0]);
    FileOutputStream cipherOutput = new FileOutputStream(args[1]);
    String password = args[2];
    long outputLength = Crypt.AES256.encrypt(plainInput, cipherOutput, password);
}

Code sample file decryption

public static void main(String[] args) throws IOException {
    FileInputStream cipherInput = new FileInputStream(args[0]);
    FileOutputStream plainOutput = new FileOutputStream(args[1]);
    String password = args[2];
    long outputLength = Crypt.Blowfish256.decrypt(cipherInput, plainOutput, password);
}

Code sample with byte arrays

byte[] plainText = { ... };
byte[] cipherText = Crypt.AES256.encrypt(plainText, "password");
byte[] plainTextAgain = Crypt.AES256.decrypt(cipherText, "password");

Usage

commons-crypt is on maven central.
So the recommended way to use it, is to add a dependency to your pom.xml:

<dependency>
    <groupId>de.mibos</groupId>
    <artifactId>commons-crypt</artifactId>
    <version>1.4</version>
</dependency>

The javadoc documentation is here: http://commonscrypt.sourceforge.net/apidocs/index.html

Required Java version

Java 7 or later