Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

Advanced hashing params #17

Open
aaronsteers opened this issue Sep 1, 2020 · 1 comment
Open

Advanced hashing params #17

aaronsteers opened this issue Sep 1, 2020 · 1 comment

Comments

@aaronsteers
Copy link

aaronsteers commented Sep 1, 2020

I want to propose some advanced hashing capabilities. Essentially the goals of these features are that: the process is 100% repeatable when it should be repeatable, and 100% non-repeatable when it shouldn't be repeatable.

Here is some sample code - but basically would like to be able to override (1) the hashing algorithm (MD5, SHA, etc.) and (2) a secret seed value to concatenate before hashing, which would prevent the process to be repeatable by persons who did not have the secret seed.

Is this agreeable? This is not a huge priority for me, but it would be a nice addition, and I would be happy to submit a PR if it sounds like a good direction overall.

@aaronsteers
Copy link
Author

aaronsteers commented Sep 1, 2020

import hashlib

HASH_FUNCTIONS = {"MD5": hashlib.md5, "SHA256": hashlib.sha256, "SHA512": hashlib.sha512}

def hash_fn(clear_value):
    fn = HASH_FUNCTIONS[config.get("hash_function", "")]
    hash_seed = config.get("hash_seed", "")
    return fn(f"{hash_seed}{clear_value}".encode("utf-8")).hexdigest()

transform():
    ...
    hashed_value = hash_fn(clear_value)
    ...

This is pulled from another project and I didn't do a lot to refactor so it might feel a tiny bit awkward. Still, hopefully it gives a good idea.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant