random - python: 16 byte token generation for authentication -


in python, need generate 16 byte(specific due machine constraints) token authentication. best way it:

  • os.urandom: takes number of bytes argument return same number of random bytes. option if same machine generates many such random number simultaneously ?
  • uuid.uuid4: str(uuid.uuid4()) of 16 byte(if not, can use uuid generate 16 byte)?

uuid.uuid4() generates 16 random bytes (using system urandom if available), output longer 16 bytes after converted printable ascii. need 16 bytes of random data, or 16 printable bytes? using token suggests latter. in case need truncate (using end rather beginning, there non-random versioning bytes @ start, , stripping hyphens no good) , realize have less 16 bytes worth of randomness.

or, base64-encode random data yourself. can fit more 16 bytes b64 b16 (hex) uuid uses (12 bytes vs 8)

urandom implementations os specific. urandom non-blocking , uses prng seeded available entropy.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -