We can encrypt data with a secret and try and preserve the format of the original data [Python]:
Node.js Format Preserving Encryption |
Theory
A sample run using a dictionary of '1234567890' is:
Message: 432143256546544 Password: qwerty Domain: [ '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' ] Cipher: 793579380870877 Decipher: 432143256546544
and for a dictionary with 'abc123':
Message: ab31132bb Password: qwerty Domain: [ 'a', 'b', 'c', '1', '2', '3' ] Cipher: 3a2cc21aa Decipher: ab31132bb
The following is some sample code
const Encryptor = require('node-fpe'); const args = process.argv.slice(3); const message= args[0]; const password= args[1]; const dom= args[2].split(''); console.log("Message:\t",message); console.log("Password:\t",password); console.log("Domain:\t\t",dom); const encryptor = new Encryptor({ password: password,domain: dom, algorithm:'aes-256-cbc' }); var rtn=encryptor.encrypt(message) console.log('\nCipher:\t\t',rtn); rtn=encryptor.decrypt(rtn) console.log('Decipher:\t',rtn);
The following is an outline of a presentation [slides]: