N.K
N.K

Reputation: 2240

Generating a Unique Key on using C#

i want to generate a unique key in my web service (WCF) , to asign to a user, it should be minimum 32bit, what is the best way to di it,

It would be asigned as a registration number for that user , and would be valid for 23 days,

i thought of using time stamp and encoding it using RSA,]

Whats would be the best practice

Regards Nakul Kundra

Upvotes: 0

Views: 360

Answers (3)

Simon Mourier
Simon Mourier

Reputation: 138960

You could use my answer to another similar question on SO: Serial numbers generation without user data

The algorithm allows to install a hidden byte in a guid (128 bits). The hidden byte could contain for example a month (from a fixed date in time, with 4 bits you can code 32 months) and a day (4 bits).

Upvotes: 0

user1921
user1921

Reputation:

I would use a Guid

var userKey = Guid.NewGuid();

In your database you'd need to store the datetime that the key was created and then implement your logic to check that to determine if the key has expired. I don't see any need to encode it based on your question.

Upvotes: 0

Oded
Oded

Reputation: 499072

Not sure what you mean and why you want to encrypt a key, but you can use a GUID for a unique key.

As for it being valid for 23 days, this is logic you need to implement.

Upvotes: 3

Related Questions