Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrating to a new salt? #26

Closed
olalonde opened this issue Sep 11, 2016 · 2 comments
Closed

Migrating to a new salt? #26

olalonde opened this issue Sep 11, 2016 · 2 comments

Comments

@olalonde
Copy link

I have the following problem. I have a PostgreSQL table with an auto incrementing ID on rows and use hashids to encode those IDs in URLs (let's say we have 1000 rows currently). However, I need to change the salt that we are using and was wondering how I might be able to do this without adding too much complexity.

One option would be to change the path prefix of URLs so that we can know which salt to use /oldpath/:hashedid (uses old salt) /newpath/:hasedid (uses new salt), that would probably be the most simple solution, but I have to chose a new path.

Another option would be to attempt to decode the hashed id with both salts:

  1. Decode with the old salt. If the decoded integer is between 0-1000 (largest ID at the time we switched to the new salt), use that integer.
  2. Otherwise, decode with new salt.

The problem however is that there might be hash collisions :( (e.g. the new salt generates a hash from X that when decoded with the old salt produces an integer Y between 0-1000, which the decoding function would recognise as an old hash).

I'm running out of imagination here and was wondering if anyone else had done this before and what strategy was used.

@jd327
Copy link
Collaborator

jd327 commented Sep 11, 2016

Another way of distinguishing is by ID length. If you know that all of your current IDs are 5 characters, then your new ones can be length 6 and up (use the padding param in constructor).

If that's not ideal, I'd go with the path route: /oldpath/v:hashedid

@olalonde
Copy link
Author

Ah yeah, that's not a bad idea, I guess I could increase size.

@jd327 jd327 closed this as completed Sep 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants