简体   繁体   中英

Storing an api_key, api_pass

I want to store a user's API_KEY and API_PASSWORD, obscured in my database. I do need to be readily view them (for authentication) and to be able to display to the user if they want to view it. What would be a good way to do this?

def create_key(self, user):
    key = str(uuid.uuid4()).replace('-','')
    key_saved_in_database = # ?
    user.key = key_saved_in_database
    user.save()

def view_key(self, user):
    key_saved_in_database = user.key
    key = # ?
    return key

What are some possible ways to do this?

A basic implementation with xoring might look like this:

def infiniteSecret(secret):
    num = 0
    while true:
        yield secret[num % len(secret)]
        num += 1
#one direction
key_saved_in_database = map(lambda a, b: a ^ b, zip(infiniteSecret(secret), key))

#other direction
key = map(lambda a, b: a ^ b, zip(infiniteSecret(secret), key_saved_in_database))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM