# SHA-256 for unique token

I need to create an unique token for a web service. I'm doing that in the following in the following way:

var element_id  // auto increment number, every time different
var secret_key  // an secret key
var random_key  // a random generated string of 8 chars, every time different
var timestamp   // the timestamp at the moment of generation

var token = element_id + secret_key + random_key + timestamp;


This will produce a string consisting of 15 to 20 characters. In my system every string generated in this way is unique.

Then I create the SHA-256 version of that string

var sha256_token=sha256(token);


Will the sha256_token be unique in my system as it was the "clear" token?

• I guess that the protocol has some overkill if it has a secret and an element_id that is "every time different" - that's all you need for creating a token. However, getting element_id to be different every time on a distributed system can be harder than initially expected (failover, reboots, single point of failure etc. etc.). – Maarten Bodewes May 13 '20 at 12:36