-1

I have an account number as string ex: "98932849294322" on which I perform a 256 Hash calling DigestUtils.sha256Hex(value) which returns a 64 char encoded string. Now I want to convert the 256 value into a number either from the 64-byte hex or raw binary from a sha-256. My purpose is to have a new number that I can use to refer to the original account number which should map one-to-one to the new number. My two questions are:

1- What function I need to call to get the number from the value returned from a sha256 call.

2- Would it be a collision from the number obtained in 1). Let say I have two accounts "1245" and "6543" would they ever generate the same hash therefore getting the same number in 1) from two different account numbers?

Thanks

Fabio
  • 555
  • 3
  • 9
  • 24
  • Does this answer your question? [how can get original value from hash value?](https://stackoverflow.com/questions/4332371/how-can-get-original-value-from-hash-value) – Progman Jun 12 '20 at 15:34
  • This does not answer my question. I already know that hashing is one way. What I don't know is if two different values can have the same hash. In this case I would not be able to use it because two different account numbers will map to the same generated id – Fabio Jun 12 '20 at 17:29
  • By definition of a hash function, two input values can have the same hash value. It might be possible that in your case you will not have any collisions, but you have to check. Since there is no reverse function you will have to use brute-force or save a mapping of the input and hash values anyway. – Progman Jun 12 '20 at 17:37

1 Answers1

0

Yes and No. No. The problem is that two different strings can render the same SHA value. Therefore only using SHA this is not possible. Yes. However if I perform extra algorithmic operations on the original string and given that the string is of limited length (12) I can generate a 32 Bit number and use something like a shift operator and then pad with the result of my custom algorithm on the string and pad the 32 extra bits to generate a unique 64 bit number.

Fabio
  • 555
  • 3
  • 9
  • 24