For the application I'm working on, I need to create a session token, which should have the following properties:
I was thinking of adapting a Guid structure with a cryptographic random number, but it could be overkill. Does anyone know / created a data structure that matches all of these properties?
. GUID , .
GUID , , . GUID , , GUID , GUID , MAC- . , GUID .
, , .
: , , . GUID , , . , GUID. GUID , .. GUID - - , , .
GUID - , , .. -, .
RandomNumberGenerator , .
RandomNumberGenerator rng = RandomNumberGenerator.Create(); byte[] bytes = new byte[8]; rng.GetBytes(bytes); // produces a string like "4jpKc52ArXU=" var s = Convert.ToBase64String(bytes);
, ASP.NET , :
using System; using System.IO; using System.Web; using System.Web.SessionState; class Program { static void Main() { var request = new HttpRequest("", "http://localhost", ""); var response = new HttpResponse(TextWriter.Null); var context = new HttpContext(request, response); var id = new SessionIDManager().CreateSessionID(context); Console.WriteLine(id); } }
, GUID - 128- , . , 64- - . , , -, .
GUID
, . - , , GUID, , , , , -.