vendredi 3 mars 2017

Which one is more secure to use? uuid, binascii.hexlify(os.urandom()) or random.SystemRandom()?

I want to create unique <client-key> and <client-secret> for the users who registers themselves for the service.

So, I was searching for the same and came up with these options:

It's a silly question but I want to know that which implementation is more secure to use (with proper explanation)? Why? And what are the advantages of using it over others?

Note: AFAIK, random.SystemRandom() uses os.urandom(x). So comparison is mainly between uuid and random.SystemRandom().


What I've tried so far:

1)

import random
temp = random.SystemRandom()
random_seq = ''.join(temp.choice(CHARACTER_SET) for x in range(x))
>>> 'wkdnP3EWxtEQWnB5XhqgNOr5RKL533vO7A40hsin'

2)

import uuid
str(uuid.uuid4())
>>> 'f26155d6-fa3d-4206-8e48-afe15f26048b'

I'm not sure about the solution. So, any help would be appreciated.


P.S. It'd be great if any solution is available for both Python 2.x and 3.x.




Aucun commentaire:

Enregistrer un commentaire