Cache Dependent Key/Encryption

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default Cache Dependent Key/Encryption

    I would like to store some Role Information in a cookie since I cannot use
    Session in the AuthenticateRequest method.

    I thought of encrypting the cookie using Rijndael Algo. for provider. I
    would generate a 16 character key store it as a Cached object and replace it
    every 20-30 minutes, if the cookie data does not decrypt then simply reload
    it because I would assume that key expired.

    Is this a secure way of doing it?


    A. Elamiri Guest

  2. Similar Questions and Discussions

    1. Image dependent on DB value.
      I've got a datagrid and one of the columns shows whether a row has been selected. If it's selected the row background color is grey and one of the...
    2. Dependent Dropdowns
      I have searched high and low and haven't found a good tutorial for doing dependent dropdowns. I have 2 tables in my DB, Cat and SubCat, Cat...
    3. Dependent DropDownLists
      I am having a problem with my datagrid. I have 2 edit columns containing DropDownLists, one dependent on another. Both lists are being populated...
    4. PUT dependent files?
      Hi there, I have clicked the option to also include the dependent files a files I want to put to the testing server. How do I un-check this...
    5. Move dependent files
      When uploading via dreamweaver I accidentally checked the "Don't Ask Me Again" checkbox, how can I undo this so I DO get prompted to upload dependent...
  3. #2

    Default Re: Cache Dependent Key/Encryption

    Perhaps you might use the Forms Authentication cookie/ticket management that
    is very similar that the one you 'd described but you don't need to warry
    about keymanagement and expiration issues. You have an example of this here:

    On your login page after the validation step, you get the roles info
    (string[] roles) and create/encrypt the cookie like this:

    HttpCookie cookie = FormsAuthentication.GetAuthCookie( UserId.Text, false );
    FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(
    cookie.Value );

    // Store roles inside the Forms cookie.
    FormsAuthenticationTicket newticket = new FormsAuthenticationTicket(
    ticket.Version,
    ticket.Name,
    ticket.IssueDate,
    ticket.Expiration,
    ticket.IsPersistent,
    String.Join( "|", roles),
    ticket.CookiePath);

    cookie.Value = FormsAuthentication.Encrypt(newticket);
    Context.Response.Cookies.Set(cookie);
    Response.Redirect( FormsAuthentication.GetRedirectUrl( newticket.Name,
    newticket.IsPersistent ) );

    On the Application_AuthenticateRequest you put this code to load you
    Principal object.

    if (Context.Request.IsAuthenticated)
    {
    // retrieve user's identity from httpcontext user
    FormsIdentity ident = (FormsIdentity)Context.User.Identity;
    // retrieve roles from the authentication ticket userdata field
    string[] arrRoles = ident.Ticket.UserData.Split(new char[] {'|'});
    // create principal and attach to user
    Context.User = new System.Security.Principal.GenericPrincipal(ident,
    arrRoles);
    }

    I hope this help.

    Regards,

    Hernan de Lahitte
    Lagash Systems S.A.
    [url]http://weblogs.asp.net/hernandl[/url]


    This posting is provided "AS IS" with no warranties, and confers no rights.

    "A. Elamiri" <abdellahDOTelamiriATclintonDOTedutNOSPAM> wrote in message
    news:um7sEnhJEHA.3728@TK2MSFTNGP12.phx.gbl...
    > I would like to store some Role Information in a cookie since I cannot use
    > Session in the AuthenticateRequest method.
    >
    > I thought of encrypting the cookie using Rijndael Algo. for provider. I
    > would generate a 16 character key store it as a Cached object and replace
    it
    > every 20-30 minutes, if the cookie data does not decrypt then simply
    reload
    > it because I would assume that key expired.
    >
    > Is this a secure way of doing it?
    >
    >

    Hernan de Lahitte Guest

  4. #3

    Default Re: Cache Dependent Key/Encryption

    Thanks!! I'll try that out

    --
    Abdellah Elamiri
    ..net Developer
    Efficacy through simplicity
    "Hernan de Lahitte" <hernan@lagash.com> wrote in message
    news:OkIeEAkJEHA.2456@TK2MSFTNGP12.phx.gbl...
    > Perhaps you might use the Forms Authentication cookie/ticket management
    that
    > is very similar that the one you 'd described but you don't need to warry
    > about keymanagement and expiration issues. You have an example of this
    here:
    >
    > On your login page after the validation step, you get the roles info
    > (string[] roles) and create/encrypt the cookie like this:
    >
    > HttpCookie cookie = FormsAuthentication.GetAuthCookie( UserId.Text,
    false );
    > FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(
    > cookie.Value );
    >
    > // Store roles inside the Forms cookie.
    > FormsAuthenticationTicket newticket = new FormsAuthenticationTicket(
    > ticket.Version,
    > ticket.Name,
    > ticket.IssueDate,
    > ticket.Expiration,
    > ticket.IsPersistent,
    > String.Join( "|", roles),
    > ticket.CookiePath);
    >
    > cookie.Value = FormsAuthentication.Encrypt(newticket);
    > Context.Response.Cookies.Set(cookie);
    > Response.Redirect( FormsAuthentication.GetRedirectUrl( newticket.Name,
    > newticket.IsPersistent ) );
    >
    > On the Application_AuthenticateRequest you put this code to load you
    > Principal object.
    >
    > if (Context.Request.IsAuthenticated)
    > {
    > // retrieve user's identity from httpcontext user
    > FormsIdentity ident = (FormsIdentity)Context.User.Identity;
    > // retrieve roles from the authentication ticket userdata field
    > string[] arrRoles = ident.Ticket.UserData.Split(new char[] {'|'});
    > // create principal and attach to user
    > Context.User = new System.Security.Principal.GenericPrincipal(ident,
    > arrRoles);
    > }
    >
    > I hope this help.
    >
    > Regards,
    >
    > Hernan de Lahitte
    > Lagash Systems S.A.
    > [url]http://weblogs.asp.net/hernandl[/url]
    >
    >
    > This posting is provided "AS IS" with no warranties, and confers no
    rights.
    >
    > "A. Elamiri" <abdellahDOTelamiriATclintonDOTedutNOSPAM> wrote in message
    > news:um7sEnhJEHA.3728@TK2MSFTNGP12.phx.gbl...
    > > I would like to store some Role Information in a cookie since I cannot
    use
    > > Session in the AuthenticateRequest method.
    > >
    > > I thought of encrypting the cookie using Rijndael Algo. for provider. I
    > > would generate a 16 character key store it as a Cached object and
    replace
    > it
    > > every 20-30 minutes, if the cookie data does not decrypt then simply
    > reload
    > > it because I would assume that key expired.
    > >
    > > Is this a secure way of doing it?
    > >
    > >
    >
    >

    A. Elamiri Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139