0
$\begingroup$

Supposed that I get an ID from third party (in this case, Telegram ID which is the range $-2^{31}$ to $2^{31}-1$). I want to store the ID securely and privately into my database by hashing it. I don't really care what the ID is, but I do really want to store the ID uniquely without actually storing the real data.

The problem is the entropy is pretty small (32-bit). Any people can get the real ID by brute forcing it. Also it is impossible to ask user to create a passphrase (or something like that) to make a derivative key, since I only get data from API and not interacting to it. I tried to figure out salting it, but since the main problem is the entropy is too small, I don't think it might work as expected.

HashIds is not a solution because the ID comes from third party.

How should I store the hash so that the hash won't be easily bruted-force? Currently, I am using SHA-512 to hash the ID.

Edit: for clarification

  • I can't store plain ID to database so that I must hash it
  • I don't need to recover original ID, but I need to check whether the hashes ID exists or not in DB, regardless the original ID
  • This has nothing to do with user. Yes it was the user ID from third party, but it is no way for user interacting with it. Thus, it is impossible to ask user for a pass phrase or something like that.

To sum up, I need to hash the ID and making it harder to brute force. Is it possible even if attacker try to brute force the entire 32 bit entropy?

$\endgroup$
  • $\begingroup$ Things depend on A) what you need to do with IDs after it is stored: comparing an alleged ID against a certain stored ID ? Searching by ID ? Recovering the original ID ? and B) what you can trust that the legitimate server or user can do that the adversary can not. Neither is clear. $\endgroup$ – fgrieu Aug 21 '17 at 11:43
  • $\begingroup$ Usually when you have an ID, you have a password. Do you have a password? $\endgroup$ – Paul Uszak Aug 21 '17 at 11:53
1
$\begingroup$

I tried to figure out salting it, but since the main problem is the entropy is too small, i don't think it might work as expected.

With your "salt" being a long, high-entropy and secret blob, it should work alright.

But even more important, don't use a single SHA512. SHAs are fast, that's bad if you want to prevent bruteforcing. There's eg. PBKDF2 or bcrypt.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.