Skip to content

Java implementation of the FE1 Format Preserving Encryption algorithm.

License

Notifications You must be signed in to change notification settings

Worldpay/java-fpe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Java implementation of the FE1 Format Preserving Encryption algorithm.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published