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

Mohsin

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().

Here's 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.

Dimitris Fasarakis Hilliard

It does not make any difference, all are of them use os.urandom both in Python 3 and 2. uuid4 just instantiates a new UUID object by passing in 16 random bytes to it:

def uuid4():
    """Generate a random UUID."""
    return UUID(bytes=os.urandom(16), version=4)

so from a standpoint of how the randomness is generated, these don't differ.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

どちらを使用するのがより安全ですか?uuid、binascii.hexlify(os.urandom())またはrandom.SystemRandom()?

分類Dev

What are the --use-urandom or --use-random options in LUKS used for?

分類Dev

verilogのurandom_range()、urandom()、random()

分類Dev

less or more - which to use when?

分類Dev

after combining more than one javascript files using online Optimizer Finally which name to use?

分類Dev

Whats the difference between os.urandom() and random?

分類Dev

MSBUILD : error MSB1011: Specify which project or solution file to use because this folder contains more than one project or solution file

分類Dev

VSTS Build Agents VS Agents installed directly on the server (Deployment Groups). Which is more secure?

分類Dev

binascii.hexlify(os.urandom(32))。decode()はどういう意味ですか?

分類Dev

Can I use more then one span in a link?

分類Dev

Which one to use in Room: LiveData or RxJava?

分類Dev

PayPal API Confusion - Which one to use for ExpressCheckout

分類Dev

Ad hoc vs Mesh, which one to use?

分類Dev

Generating Predictable Secure Random Numbers

分類Dev

Secure Password Generation With Random Chars

分類Dev

Get secure random value in rspec

分類Dev

Which is the more efficient way to choose a random pair of objects from a list of lists or tuples?

分類Dev

Which is the more efficient way to choose a random pair of objects from a list of lists or tuples?

分類Dev

Writing a binary file with lines more than 45 bytes: binascii.Error: At most 45 bytes at once

分類Dev

node.js and express: use more than one views directory

分類Dev

How to use Java optional operator to map more than one subtype

分類Dev

use a dynamic jQuery function for more than one Field and div

分類Dev

How to use lookahead and lookbehind in more than one capturing group

分類Dev

Use more than one post meta inside the loop

分類Dev

Python SystemRandom / os.urandomは常に、優れた暗号化に十分なエントロピーを持ちますか

分類Dev

Use npm uuid in reactjs

分類Dev

Differences BW Facebook Login and FBSDKLoginKit Pod and which one to use?

分類Dev

Python interpreters on OS X Yosemite - which one to use?

分類Dev

How to know which cuDNN version one should use?

Related 関連記事

  1. 1

    どちらを使用するのがより安全ですか?uuid、binascii.hexlify(os.urandom())またはrandom.SystemRandom()?

  2. 2

    What are the --use-urandom or --use-random options in LUKS used for?

  3. 3

    verilogのurandom_range()、urandom()、random()

  4. 4

    less or more - which to use when?

  5. 5

    after combining more than one javascript files using online Optimizer Finally which name to use?

  6. 6

    Whats the difference between os.urandom() and random?

  7. 7

    MSBUILD : error MSB1011: Specify which project or solution file to use because this folder contains more than one project or solution file

  8. 8

    VSTS Build Agents VS Agents installed directly on the server (Deployment Groups). Which is more secure?

  9. 9

    binascii.hexlify(os.urandom(32))。decode()はどういう意味ですか?

  10. 10

    Can I use more then one span in a link?

  11. 11

    Which one to use in Room: LiveData or RxJava?

  12. 12

    PayPal API Confusion - Which one to use for ExpressCheckout

  13. 13

    Ad hoc vs Mesh, which one to use?

  14. 14

    Generating Predictable Secure Random Numbers

  15. 15

    Secure Password Generation With Random Chars

  16. 16

    Get secure random value in rspec

  17. 17

    Which is the more efficient way to choose a random pair of objects from a list of lists or tuples?

  18. 18

    Which is the more efficient way to choose a random pair of objects from a list of lists or tuples?

  19. 19

    Writing a binary file with lines more than 45 bytes: binascii.Error: At most 45 bytes at once

  20. 20

    node.js and express: use more than one views directory

  21. 21

    How to use Java optional operator to map more than one subtype

  22. 22

    use a dynamic jQuery function for more than one Field and div

  23. 23

    How to use lookahead and lookbehind in more than one capturing group

  24. 24

    Use more than one post meta inside the loop

  25. 25

    Python SystemRandom / os.urandomは常に、優れた暗号化に十分なエントロピーを持ちますか

  26. 26

    Use npm uuid in reactjs

  27. 27

    Differences BW Facebook Login and FBSDKLoginKit Pod and which one to use?

  28. 28

    Python interpreters on OS X Yosemite - which one to use?

  29. 29

    How to know which cuDNN version one should use?

ホットタグ

アーカイブ