Crates.io | field-encryption |
lib.rs | field-encryption |
version | 0.0.1 |
source | src |
created_at | 2022-11-08 23:37:13.749764 |
updated_at | 2022-11-09 10:12:04.035938 |
description | A library for formattable field encyption. |
homepage | |
repository | https://github.com/vladimir-ea/field-encryption |
max_upload_size | |
id | 708383 |
size | 22,160 |
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:
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.