Skip to main content

Format Preserving Encryption with FF1 and FF3-1

Project description

Installation

This library uses PyCryptodome which means a C compiler is required. For Mac and Linux users this is already installed. For Windows users please follow this guide from PyCryptoDome.

https://pycryptodome.readthedocs.io/en/latest/src/installation.html#windows-from-sources

Usage

The libray is imported as from FPE import FPE.

To generate a tweak use FPE.generate_tweak(tweak_length) where tweak_len is the length of the tweak in bytes. Note that for FF3-1 the tweak_length must be 7 bytes.

To generate a key use FPE.generate_key(), this will generate a 16 byte key.

To make a cipher object use cipher = FPE.New(key,tweak,mode)

Currently supported modes are FPE.Mode.FF1 and FPE.Mode.FF3-1

To encrypt use cipher.encrypt(plaintext,format)

Currently supported formats are:

FPE.Format.DIGITS FPE.Format.CREDITCARD FPE.Format.LETTERS FPE.Format.STRING FPE.Format.EMAIL FPE.Format.CPR

to decrypt use cipher.decrypt(ciphertext,format)

The library also supports CSV files

To encrypt a csv file use cipher.encryptCSV(InputFilePath,OutputFilePath,formats) where formats is a list of formats sorted by the columns

To decrypt a csv file use cipher.decryptCSV(InputFilePath,OutputFilePath,formats)

to generate a random CSV file with certain formats use cipher.generateData(OutputFilePath,rows,formats,variables) where rows define the number of rows in the CSV file. Formats is the lists of formats to use. Variables is the list of variable names used for the first row.

Examples

Example of encrypting and decrypting "12345" as DIGITS and printing the output

from FPE import FPE

if __name__ == '__main__':

	T = FPE.generate_tweak(8)
	
	key = FPE.generate_key()
	
	cipher = FPE.New(key,T,FPE.Mode.FF1)
	
	ciphertext = cipher.encrypt('12345',FPE.Format.DIGITS)
	
	print(ciphertext)
	
	plaintext = cipher.decrypt(ciphertext,FPE.Format.DIGITS)
	
	print(plaintext)

Example of generating, encrypting and decrypting a 1000 row CSV file

from FPE import FPE, Format

variables = [
	'Username','Password','Email','PhoneNumber','Cpr-number',
	'Creditcard','adress','city','zip','country'
]


formats = [
	Format.LETTERS, Format.STRING, Format.EMAIL, Format.DIGITS,
	Format.CPR, Format.CREDITCARD,Format.STRING,Format.LETTERS,
	Format.DIGITS,Format.LETTERS
]

if __name__ == '__main__':
	
	T = FPE.generate_tweak(7)
	key = FPE.generate_key()
	cipher = FPE.New(key,T,FPE.Mode.FF3)
	cipher.generateData('testData.csv',1000,formats,variables)
	cipher.encryptCSV('src/testData.csv','src/encryptedData.csv',formats)
	cipher.decryptCSV('src/encryptedData.csv','src/decryptedData.csv',formats)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

FPE-0.1.0.tar.gz (120.9 kB view details)

Uploaded Source

Built Distribution

FPE-0.1.0-cp39-cp39-win_amd64.whl (83.7 kB view details)

Uploaded CPython 3.9Windows x86-64

File details

Details for the file FPE-0.1.0.tar.gz.

File metadata

  • Download URL: FPE-0.1.0.tar.gz
  • Upload date:
  • Size: 120.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.8

File hashes

Hashes for FPE-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0eecd47228ab662082ea4f4197bd954b41435dabffedc2d5e672f7500206e561
MD5 9fde56cc65713b43957f478ced93d2d0
BLAKE2b-256 89aa0ca1012bf4ec898da720b1febf4544ab1b2b9adf6cb10f0b33b845ff05ed

See more details on using hashes here.

File details

Details for the file FPE-0.1.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: FPE-0.1.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 83.7 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.8

File hashes

Hashes for FPE-0.1.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 32975400b5db686111993651b0946793e8bf72320bfdd8f751f84b72223c33d7
MD5 2961997ca53579055ab09fb3b6f33fe0
BLAKE2b-256 e81dc17b562f4ae77a809c248393ef3ce519deb1ea4a6091103a057442d8110b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page