Giter Site home page Giter Site logo

java-fpe's Introduction

java-fpe

A Java implementation of Format Preserving Encryption using the FE1 scheme from the paper "Format-Preserving Encryption" by Bellare, Rogaway, et al.

Ported from DotFPE; which was ported from Botan Library Version 1.10.3.

See LICENSE.md for the full license.

Basic Usage

/**
 * Sample code to round trip a number using FE1.
 * @throws FPEException If anything goes wrong.
 */
public void demoRoundTrip() throws FPEException {
	FE1 fe1 = new FE1();
	
	// The range of plaintext and ciphertext values 
	BigInteger modulus = new BigInteger("9999999999999999", 10);
	
	// A value to encrypt 
	BigInteger plaintextValue = new BigInteger("4444333322221111", 10);
	
	// A key, that will be used with the HMAC(SHA256) algorithm, note that this is not secure!
	byte[] hmacKey = new byte[] { 0x10, 0x20, 0x10, 0x20, 0x10, 0x20, 0x10, 0x20};
	
	// An initialisation vector, or tweak, used in the algorithm.
	byte[] iv = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
	
	BigInteger encryptedValue = fe1.encrypt(modulus, plaintextValue, hmacKey, iv);
	BigInteger decryptedValue = fe1.decrypt(modulus, encryptedValue, hmacKey, iv);
	
	System.out.println(String.format("Encrypted %s to %s and decrypted to %s", plaintextValue, encryptedValue,decryptedValue));
}

How to build

You'll need Apache Ant and Apache Ivy to build. Running ant in the project root will download, build, package and run all the unit tests.

Note that the ant script includes calls to Git to pull the commit hash and version number (tag) from the repo when building a new distribution.

Dependencies

The main code (in src) doesn't have any dependencies outside of the standard Java APIs (including JCE extensions).

However, the unit tests make use of the following:

  1. Logback provides the logging implementation.
  2. slf4j provides the logging API.
  3. hamcrest-core-1.3 and Junit 4.11 provide unit test support.

See LICENSE.md for details of the associated licenses and restrictions associated with these dependencies.

Copyright

Copyright Worldpay Ltd.

java-fpe's People

Contributors

andybrodie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  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.