field-encryption

Crates.iofield-encryption
lib.rsfield-encryption
version0.0.1
sourcesrc
created_at2022-11-08 23:37:13.749764
updated_at2022-11-09 10:12:04.035938
descriptionA library for formattable field encyption.
homepage
repositoryhttps://github.com/vladimir-ea/field-encryption
max_upload_size
id708383
size22,160
(vladimir-ea)

documentation

README

Field Encryption

This library provides a FieldEncryption struct that allows values in an input format to be encrypted into values in an output format, where the input and output formats are described by regular expressions. So it is similar to a Format Preserving Encryption scheme but allows for flexibility in the format of the encrypted fields.

use field_encryption::FieldEncryption;

let fe = FieldEncryption::new(r"[A-Z][a-z]{1,4} [A-Z][a-z]{1-4}!", r"[a-z]{5} [a-z]{7}", &[0;32]).unwrap();
let cipher_text = fe.encrypt("Hello World!").unwrap();
println!("{}", cipher_text);
let plain_text = fe.decrypt(&cipher_text).unwrap(); 
println!("{}", plain_text);

Gives the output:

qtzwe mcdzozq
Hello World!

The implementation is based on the 'Ciphers with Arbitrary Finite Domains' paper by Black and Rogaway (2002), and works as follows:

  • the offset of the input in the variants of the input regex is calculated
  • the offset is encrypted into the domain of the output regex using a Fiestal network
    • the 'cycle walking' approach outlined in the paper is used to arrive at inbounds values
  • the output of the encryption is used as an offset 'n' in the variants of the output regex
  • the nth variant of the output regex is returned as the cipher text

Uses

This library might be useful for tokenizing data fields in a way that is compliant with existing data schemas, in order ot anonymize a dataset, for example.

Limitations

  • I am not a cryptographer! There is no guarantee whatsoever that this library is cryptographically secure.
Commit count: 4

cargo fmt