Re: get hexadecimal hash string for a number
On 9/20/2012 5:30 AM, Magnus Warker wrote:
As has been pointed out, integers are already unique. Just decide on
a large enough fixed size and zero pad the small numbers:
0000000000001
If you want to disguise the actual number you are using, which is what
I take your mention of "hash" to mean, then you need an encryption.
Each unique input gives a unique output. It has to be unique,
otherwise you couldn't decrypt it reliably.
What about Kevin's posting? He noted that encrypting sequential numbers
would reveal the encryption key?
That type of attack is called a known plaintext attack. The most
common symmetric encryption algorithm AES should not be vulnerable
to that.
But as previous stated then I only consider that second best solution.
For 64 bit numbers, just use DES and encrypt the numbers 0, 1, 2, 3,
... n in turn. For 128 bits use AES.
Could you please explain this? I haven't used encryption in Java, but I
would expect that the encryption method should be independend of the
size of the data to encrypt?
DES operates on 8 byte blocks and AES on 16 byte blocks.
For data that is not a multipla of that padding is required.
But I would suggest AES and padding.
Again, you will need to be sure that your chosen bit size will
acommodate enough users, with plenty to spare for keeping the gaps
numerous enough.
Well, I would simply choose the size of SQL standard integer (64)...
In many databases INTEGER is only 32 bit.
64 bit is called BIGINT or something similar.
Arne