CryptGenRandom to generate asp.net session id

Posted by DoDo on Stack Overflow See other posts from Stack Overflow or by DoDo
Published on 2010-01-15T10:26:19Z Indexed on 2010/04/07 0:03 UTC
Read the original article Hit count: 240

Filed under:
|
|
|

Hi!

does anyone have working example of CryptGenrRandom class to generate session id (need to use in my iis module).

HCRYPTPROV   hCryptProv;    
BYTE         pbData[16];

if(CryptAcquireContext( &hCryptProv,  NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) 
{       
    if(CryptGenRandom(hCryptProv, 8, pbData)) 
    {
        std::string s(( const char *) pbData);  
        printf(s.c_str());
    }
    else
    {
        MyHandleError("Error during CryptGenRandom.");
    }
}
else
{
    MyHandleError("Error during CryptAcquireContext!\n");
}   

i tried this code but, its not working quite well (i get it from msdn) and this example don't work for me ( http://www.codeproject.com/KB/security/plaintextsessionkey.aspx )

so if anyone know how to generate sessionid using this class plz let me know

tnx anyway!

© Stack Overflow or respective owner

Related posts about session

Related posts about id