Giter Site home page Giter Site logo

aerogear-crypto-java's Introduction

Build Status

AeroGear Crypto Java

A Java API to provide an easy way to use cryptography interfaces for developers built on top of javax.crypto and Bouncy Castle to support: AES-GCM authenticated encryption, password based key derivation and elliptic curve cryptography.

Requirements

Installation

Android

The Android platform unfortunately ships an incomplete and outdated version of Bouncy Castle for Android which also makes hard to install an updated version of the library. That said, we had to stick with Spongy Castle, a version of Bouncy Castle repackaged to make it work on Android.

<dependency>
    <groupId>org.jboss.aerogear</groupId>
    <artifactId>aerogear-crypto</artifactId>
    <version>0.1.3</version>
    <classifier>android</classifier>
</dependency>

Regular Java projects

For regular Java EE and Java SE projects, Bouncy Castle will be supported and there is no need to workaround it.

<dependency>
    <groupId>org.jboss.aerogear</groupId>
    <artifactId>aerogear-crypto</artifactId>
    <version>0.1.3</version>
</dependency>

<dependency>
    <groupId>bouncycastle</groupId>
    <artifactId>bcprov-jdk16</artifactId>
    <version>140</version>
</dependency>

Getting started

AeroGear Crypto does not reinvent the wheel by writing encryption algorithms or creating protocols, we still have some sanity. The major goal of this project is to provide simple API interfaces for uber complicated parameters, so let's get started.

Password based key derivation

Pbkdf2 pbkdf2 = AeroGearCrypto.pbkdf2();
byte[] rawKey = pbkdf2.encrypt("passphrase");

Symmetric encryption

//Generate the key
Pbkdf2 pbkdf2 = AeroGearCrypto.pbkdf2();
byte[] privateKey = pbkdf2.encrypt("passphrase");

//Initializes the crypto box
CryptoBox cryptoBox = new CryptoBox(privateKey);

//Encryption
byte[] IV = new Random().randomBytes();
byte[] ciphertext = cryptoBox.encrypt(IV, "My bonnie lies over the ocean");

//Decryption
CryptoBox pandora = new CryptoBox(privateKey);
byte[] message = pandora.decrypt(IV, ciphertext);

Asymmetric encryption

//Create a new key pair
KeyPair keyPairBob = new KeyPair();
KeyPair keyPairAlice = new KeyPair();

//Initializes the crypto box
CryptoBox cryptoBox = new CryptoBox(keyPairBob.getPrivateKey(), keyPairAlice.getPublicKey());

byte[] IV = new Random().randomBytes();
byte[] ciphertext = cryptoBox.encrypt(IV, "My bonnie lies over the ocean");

//Is possible to use the same crypto box instance, but won't happen in real life
CryptoBox pandora = new CryptoBox(keyPairAlice.getPrivateKey(), keyPairBob.getPublicKey());
byte[] message = pandora.decrypt(IV, ciphertext);

We are big believers that there is too much to improve, for this reason you are more than welcome to file a JIRA if you find any issue or discuss the improvements on the mailing list. Security is not an island and it is our responsibility like developers to make it better.

aerogear-crypto-java's People

Contributors

danielpassos avatar matzew avatar qmx avatar sebastienblanc avatar secondsun avatar vibe13 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.