I need to generate a API key and Secret that would be stored in a Redis server. What would be the best way to generate a key and secret?
I am develop a Django-tastyp
Adding answer as I can't comment on T. Opletals answer.
You should not use random.choice as random isn't cryptographically secure. A better option would be random.SystemRandom() which uses the system source of randomness, on linux this would be urandom.
def generate_key(length):
char_set = string.ascii_letters + string.punctuation
urand = random.SystemRandom()
return ''.join([urand.choice(char_set) for _ in range(length)])