Search code examples
hashids

Why Hashids can be decoded?


I've used this popular library Hashids.

As this poster mentioned,Hashes produced by these algorithms are designed to be 'one-way'. Then, why is it possible for a hash value to be decoded?

I've read the documentation (and searched the issues), but don't see why hashes created by this library can be decoded.

I was about to ask this question in the git repo, but this is a question rather than an issue.

Any insight will be appreciated.


Solution

  • You find the reason in the documentation on the project site:

    How does it work?
    Hashids works similarly to the way integers are converted to hex, but with a few exceptions:
    The alphabet is not base16, but base base62 by default.
    The alphabet is also shuffled based on salt.

    So, in short, this is not a hash at all, but merely an alternate encoding, more similar to a simple substitution cipher than to a hash (which would work as compression function). Which is, of course, pretty trivially reversible.