I am asking this question from a perspective that we need to store a set of hashed data that can be queried later for in an ordered fashion.

My situation is that some data has to be encrypted, I am thinking is there any function that I can store the ordering information relative to other data without getting the original value. So that I can sort the collection without original value but with another hashed value or any information that does not leak details on the original value.

process expected:
Saving A -> store encrypted(A) , store hash(A)
Saving B -> store encrypted(B) , store hash(B)
Saving C -> store encrypted(C) , store hash(C)

Sort List:
if hash(A) < hash(B) < hash(C) then returns [ C, B , A ]

Any hashing function or another function that can do this mathematically ?

lets assume A or B is always numeric based value.

  • $\begingroup$ So you want hash(X) < hash(Y) iff X < Y, correct? $\endgroup$ – PyRulez Aug 19 '15 at 4:11
  • $\begingroup$ Yes. But has the property of hashing function that is not reversible. $\endgroup$ – Seng Zhe Aug 19 '15 at 4:12
  • $\begingroup$ If the hash function is order-preserving, and an attacker knows the hash function and hash(X), then they can recover the most significant part of X by binary search. Is that acceptable? $\endgroup$ – Chris Culter Aug 19 '15 at 5:11
  • $\begingroup$ Sorry, I am not familiar with the term 'significant part'. Can you take an example like A as 11323 , what is the significant part? $\endgroup$ – Seng Zhe Aug 19 '15 at 5:23
  • $\begingroup$ The most significant part of some data is the part that most affects the sort order. For a five-digit number 11323, the first three digits 113__ are more significant than the last two digits ___23. The exact amount of data recoverable from a hash depends on the length of the hash. $\endgroup$ – Chris Culter Aug 19 '15 at 5:27

Your Answer

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

Browse other questions tagged or ask your own question.