Can zlib.crc32 or zlib.adler32 be safely used to mask primary keys in URLs?

Posted by David Eyk on Stack Overflow See other posts from Stack Overflow or by David Eyk
Published on 2010-04-09T20:27:00Z Indexed on 2010/04/09 21:13 UTC
Read the original article Hit count: 447

Filed under:
|
|
|
|

In Django Design Patterns, the author recommends using zlib.crc32 to mask primary keys in URLs. After some quick testing, I noticed that crc32 produces negative integers about half the time, which seems undesirable for use in a URL. zlib.adler32 does not appear to produce negatives, but is described as "weaker" than CRC.

  1. Is this method (either CRC or Adler-32) safe for usage in a URL as an alternate to a primary key? (i.e. is it collision-safe?)
  2. Is the "weaker" Adler-32 a satisfactory alternative for this task?
  3. How the heck do you reverse this?! That is, how do you determine the original primary key from the checksum?

© Stack Overflow or respective owner

Related posts about python

Related posts about zlib