Algorithm for creating unique (possibly automatically increasing) identifiers

I need to create unique identifiers for my application, and I am looking for suitable algorithms. I would prefer something like this -

YYYY + MM + DD + HH + MM + SS + <random salt> + <something derived from the preceding values>

f.ex. -

20100128184544ewbhk4h3b45fdg544

I was thinking about using SHA-256 or something, but the resulting string should not be too long. I could use the UUID , but again, they are too long, and they are guaranteed to be unique on only one machine.

I would welcome suggestions, ideas. My programming language is Java.

Edit: Ides should not be cryptographically secure. I look at simpler hash algons like Dan Bernstein etc.

+1
source share
4 answers

So, I finally decided for this -

 d = YYYYMMDDHHMMSS hash = d + sha256(d + random_salt)[:10] 

Thanks to everyone for the answer.

0
source

Try the following:

 java.security.messageDigest() 
0
source

You can use this SHA-256, and then take the first 10 bytes from the result (or as much as you like, balancing the length and uniqueness as you like).

0
source

I think that if you use SHA1 (MD5 (YYYYMMDDHHMMSS + YourSystemName + ClientName)), you will be fine with 40 characters ..;)

-1
source

Source: https://habr.com/ru/post/1306675/


All Articles