0

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

N.K
  • 2,220
  • 1
  • 14
  • 44

3 Answers3

3

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.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
0

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.

0

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).

Community
  • 1
  • 1
Simon Mourier
  • 132,049
  • 21
  • 248
  • 298