12345678910111213141516 |
- def apply(config, val):
- """ Pseudonymize using format preserving encryption.
- Example config:
- {
- 'func': 'fpe',
- 'key': 'some-secret-key',
- 'alphabet': string.ascii_letters
- }
- """
- validate_func_params(config, MANDATORY_CONFIG_PARAMS)
- try:
- alphabet = config.get('alphabet', string.printable)
- e = pyffx.String(config['key'].encode("utf-8"), alphabet, length=len(val))
- return e.encrypt(val)
- except ValueError:
- raise PseudoFuncError("Could not pseudonymize '{0}'. Check alphabet compatibility ({1})".format(val, alphabet))
|