开发者

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


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜