variables / application[]-object

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Patrick

    #1

    variables / application[]-object

    Hi

    I have the following problem. When starting my asp.net application, i read a
    encrypted string from a file, decrypt it and want this values to be
    available in the complete application. they should be stored in a global
    variable, but it shouldn't be possible to modify this variable.

    so what i tried first was using the application object to store that string.
    that was fine, but the problem is, that it can be modified from outside, so
    it's not good for my use.

    next idea was to create a public string that returns the private string with
    the get{} method. this works fine, but the problem is, where do i store the
    string, that i don't lose it. i mean, how can i store the decrypted string
    in the variable, without reading it each time from the file and decrypting
    it. i want to store it in the private variable and it should always be
    there, as long as the application is running.

    any ideas?

    Thanks


  • Patrick

    #2
    Re: variables / application[]-object

    Karl, thnanks for your answer. but as I see in your example, you add the
    secret string to the application object? so that was what i was thinking,
    that i have to add it there. there is no way to keep it in memory as
    readonly. in the application_sta rt i want to read the file, decrypt that
    info, store it to a read-only global variable, that i can access from every
    aspx page.

    as i understand you, in the application_sta rt i load the string to the
    session variable (crypted) and each time i request the public readonly
    variable, it will be decrypted.

    right?

    but in that case, people still can modify the application object and clear
    the crypted string.

    or do i missunderstand you?

    thanks for your help


    "Karl Seguin" <kseguin##crea. ca> schrieb im Newsbeitrag
    news:eihoKq6RDH A.1868@TK2MSFTN GP11.phx.gbl...[color=blue]
    > You shouldn't cary around sensitive data in the application object...it[/color]
    gets[color=blue]
    > dumped when page.trace=true .
    >
    > you may want to look at this article (amongst others):
    >[/color]
    http://msdn.microsoft.com/asp.net/de...#c14618429_011[color=blue]
    >
    > Finally, the quickest solution to your problem would be to cache (say in[/color]
    the[color=blue]
    > application variable if you can't find a better place) an instance the
    > object that contains your string..you can create the object, decrypt the
    > string, and store it in memory on application_Sta rt
    >
    > Dim SecretString as new MySecretStringO bject
    > SecretString.De crypt()
    > application.add ("SecretString" , SecretString)
    >
    > As you can image, the decrypt function decrypts the string and stores it[/color]
    in[color=blue]
    > a private field. And you have a public readonly property to read from it.
    >
    > Karl
    >
    >
    > "Patrick" <patrick911@blu email.ch> wrote in message
    > news:1057913484 .254447@fuchs.c yberlink.ch...[color=green]
    > > Hi
    > >
    > > I have the following problem. When starting my asp.net application, i[/color][/color]
    read[color=blue]
    > a[color=green]
    > > encrypted string from a file, decrypt it and want this values to be
    > > available in the complete application. they should be stored in a global
    > > variable, but it shouldn't be possible to modify this variable.
    > >
    > > so what i tried first was using the application object to store that[/color]
    > string.[color=green]
    > > that was fine, but the problem is, that it can be modified from outside,[/color]
    > so[color=green]
    > > it's not good for my use.
    > >
    > > next idea was to create a public string that returns the private string[/color]
    > with[color=green]
    > > the get{} method. this works fine, but the problem is, where do i store[/color]
    > the[color=green]
    > > string, that i don't lose it. i mean, how can i store the decrypted[/color][/color]
    string[color=blue][color=green]
    > > in the variable, without reading it each time from the file and[/color][/color]
    decrypting[color=blue][color=green]
    > > it. i want to store it in the private variable and it should always be
    > > there, as long as the application is running.
    > >
    > > any ideas?
    > >
    > > Thanks
    > >
    > >[/color]
    >
    >[/color]


    Comment

    • Karl Seguin

      #3
      Re: variables / application[]-object

      you don't load the string in the application variable, you load the entire
      object...which means the string is still private (or readonly via the
      property). However, the object can still be removed...or replaced with
      something else - as you've pointed out.

      You could implement a readonly static field...but then you could get into
      threading issues.

      How about this:

      implement a class with a single shared/statis function. something like
      this:

      public function GetSecret() as string
      dim secret as string = cstr(cache("mys ecretstring"))
      if secret is nothing then
      secret = DECRYPTSTRING() 'some private shared function
      cache.add("myse cretstring", secret, New
      System.Web.Cach ing.CacheDepend ency("FILETHATH OLDSYOURSTRING" ),
      Caching.Cache.N oAbsoluteExpira tion, Caching.Cache.N oSlidingExpirat ion,
      CacheItemPriori ty.Normal, Nothing)
      end if
      return string
      end function


      Yes, people can still manipulate teh cache and screw around with it...as far
      as I know..there's no way to create a readonly cache...though atleast it's a
      bit obfuscated. You've also moved the string away from the application and
      into the cache..which I think is good.

      There are callback methods you can use whenever the cache drops an
      item..never used them..,maybe the could come in handy...dunno.

      Karl

      "Patrick" <patrick911@blu email.ch> wrote in message
      news:1057930848 .858276@fuchs.c yberlink.ch...[color=blue]
      > Karl, thnanks for your answer. but as I see in your example, you add the
      > secret string to the application object? so that was what i was thinking,
      > that i have to add it there. there is no way to keep it in memory as
      > readonly. in the application_sta rt i want to read the file, decrypt that
      > info, store it to a read-only global variable, that i can access from[/color]
      every[color=blue]
      > aspx page.
      >
      > as i understand you, in the application_sta rt i load the string to the
      > session variable (crypted) and each time i request the public readonly
      > variable, it will be decrypted.
      >
      > right?
      >
      > but in that case, people still can modify the application object and clear
      > the crypted string.
      >
      > or do i missunderstand you?
      >
      > thanks for your help
      >
      >
      > "Karl Seguin" <kseguin##crea. ca> schrieb im Newsbeitrag
      > news:eihoKq6RDH A.1868@TK2MSFTN GP11.phx.gbl...[color=green]
      > > You shouldn't cary around sensitive data in the application object...it[/color]
      > gets[color=green]
      > > dumped when page.trace=true .
      > >
      > > you may want to look at this article (amongst others):
      > >[/color]
      >[/color]
      http://msdn.microsoft.com/asp.net/de...#c14618429_011[color=blue][color=green]
      > >
      > > Finally, the quickest solution to your problem would be to cache (say in[/color]
      > the[color=green]
      > > application variable if you can't find a better place) an instance the
      > > object that contains your string..you can create the object, decrypt the
      > > string, and store it in memory on application_Sta rt
      > >
      > > Dim SecretString as new MySecretStringO bject
      > > SecretString.De crypt()
      > > application.add ("SecretString" , SecretString)
      > >
      > > As you can image, the decrypt function decrypts the string and stores it[/color]
      > in[color=green]
      > > a private field. And you have a public readonly property to read from[/color][/color]
      it.[color=blue][color=green]
      > >
      > > Karl
      > >
      > >
      > > "Patrick" <patrick911@blu email.ch> wrote in message
      > > news:1057913484 .254447@fuchs.c yberlink.ch...[color=darkred]
      > > > Hi
      > > >
      > > > I have the following problem. When starting my asp.net application, i[/color][/color]
      > read[color=green]
      > > a[color=darkred]
      > > > encrypted string from a file, decrypt it and want this values to be
      > > > available in the complete application. they should be stored in a[/color][/color][/color]
      global[color=blue][color=green][color=darkred]
      > > > variable, but it shouldn't be possible to modify this variable.
      > > >
      > > > so what i tried first was using the application object to store that[/color]
      > > string.[color=darkred]
      > > > that was fine, but the problem is, that it can be modified from[/color][/color][/color]
      outside,[color=blue][color=green]
      > > so[color=darkred]
      > > > it's not good for my use.
      > > >
      > > > next idea was to create a public string that returns the private[/color][/color][/color]
      string[color=blue][color=green]
      > > with[color=darkred]
      > > > the get{} method. this works fine, but the problem is, where do i[/color][/color][/color]
      store[color=blue][color=green]
      > > the[color=darkred]
      > > > string, that i don't lose it. i mean, how can i store the decrypted[/color][/color]
      > string[color=green][color=darkred]
      > > > in the variable, without reading it each time from the file and[/color][/color]
      > decrypting[color=green][color=darkred]
      > > > it. i want to store it in the private variable and it should always be
      > > > there, as long as the application is running.
      > > >
      > > > any ideas?
      > > >
      > > > Thanks
      > > >
      > > >[/color]
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Patrick

        #4
        Re: variables / application[]-object

        Karl, thanks for your help. The caching solution works fine for my needs and
        was just a quick thing to implement.

        So thanks for your great help

        Patrick



        "Karl Seguin" <kseguin##crea. ca> schrieb im Newsbeitrag
        news:%23fCS217R DHA.704@tk2msft ngp13.phx.gbl.. .[color=blue]
        > you don't load the string in the application variable, you load the entire
        > object...which means the string is still private (or readonly via the
        > property). However, the object can still be removed...or replaced with
        > something else - as you've pointed out.
        >
        > You could implement a readonly static field...but then you could get into
        > threading issues.
        >
        > How about this:
        >
        > implement a class with a single shared/statis function. something like
        > this:
        >
        > public function GetSecret() as string
        > dim secret as string = cstr(cache("mys ecretstring"))
        > if secret is nothing then
        > secret = DECRYPTSTRING() 'some private shared function
        > cache.add("myse cretstring", secret, New
        > System.Web.Cach ing.CacheDepend ency("FILETHATH OLDSYOURSTRING" ),
        > Caching.Cache.N oAbsoluteExpira tion, Caching.Cache.N oSlidingExpirat ion,
        > CacheItemPriori ty.Normal, Nothing)
        > end if
        > return string
        > end function
        >
        >
        > Yes, people can still manipulate teh cache and screw around with it...as[/color]
        far[color=blue]
        > as I know..there's no way to create a readonly cache...though atleast it's[/color]
        a[color=blue]
        > bit obfuscated. You've also moved the string away from the application[/color]
        and[color=blue]
        > into the cache..which I think is good.
        >
        > There are callback methods you can use whenever the cache drops an
        > item..never used them..,maybe the could come in handy...dunno.
        >
        > Karl
        >
        > "Patrick" <patrick911@blu email.ch> wrote in message
        > news:1057930848 .858276@fuchs.c yberlink.ch...[color=green]
        > > Karl, thnanks for your answer. but as I see in your example, you add the
        > > secret string to the application object? so that was what i was[/color][/color]
        thinking,[color=blue][color=green]
        > > that i have to add it there. there is no way to keep it in memory as
        > > readonly. in the application_sta rt i want to read the file, decrypt that
        > > info, store it to a read-only global variable, that i can access from[/color]
        > every[color=green]
        > > aspx page.
        > >
        > > as i understand you, in the application_sta rt i load the string to the
        > > session variable (crypted) and each time i request the public readonly
        > > variable, it will be decrypted.
        > >
        > > right?
        > >
        > > but in that case, people still can modify the application object and[/color][/color]
        clear[color=blue][color=green]
        > > the crypted string.
        > >
        > > or do i missunderstand you?
        > >
        > > thanks for your help
        > >
        > >
        > > "Karl Seguin" <kseguin##crea. ca> schrieb im Newsbeitrag
        > > news:eihoKq6RDH A.1868@TK2MSFTN GP11.phx.gbl...[color=darkred]
        > > > You shouldn't cary around sensitive data in the application[/color][/color][/color]
        object...it[color=blue][color=green]
        > > gets[color=darkred]
        > > > dumped when page.trace=true .
        > > >
        > > > you may want to look at this article (amongst others):
        > > >[/color]
        > >[/color]
        >[/color]
        http://msdn.microsoft.com/asp.net/de...#c14618429_011[color=blue][color=green][color=darkred]
        > > >
        > > > Finally, the quickest solution to your problem would be to cache (say[/color][/color][/color]
        in[color=blue][color=green]
        > > the[color=darkred]
        > > > application variable if you can't find a better place) an instance the
        > > > object that contains your string..you can create the object, decrypt[/color][/color][/color]
        the[color=blue][color=green][color=darkred]
        > > > string, and store it in memory on application_Sta rt
        > > >
        > > > Dim SecretString as new MySecretStringO bject
        > > > SecretString.De crypt()
        > > > application.add ("SecretString" , SecretString)
        > > >
        > > > As you can image, the decrypt function decrypts the string and stores[/color][/color][/color]
        it[color=blue][color=green]
        > > in[color=darkred]
        > > > a private field. And you have a public readonly property to read from[/color][/color]
        > it.[color=green][color=darkred]
        > > >
        > > > Karl
        > > >
        > > >
        > > > "Patrick" <patrick911@blu email.ch> wrote in message
        > > > news:1057913484 .254447@fuchs.c yberlink.ch...
        > > > > Hi
        > > > >
        > > > > I have the following problem. When starting my asp.net application,[/color][/color][/color]
        i[color=blue][color=green]
        > > read[color=darkred]
        > > > a
        > > > > encrypted string from a file, decrypt it and want this values to be
        > > > > available in the complete application. they should be stored in a[/color][/color]
        > global[color=green][color=darkred]
        > > > > variable, but it shouldn't be possible to modify this variable.
        > > > >
        > > > > so what i tried first was using the application object to store that
        > > > string.
        > > > > that was fine, but the problem is, that it can be modified from[/color][/color]
        > outside,[color=green][color=darkred]
        > > > so
        > > > > it's not good for my use.
        > > > >
        > > > > next idea was to create a public string that returns the private[/color][/color]
        > string[color=green][color=darkred]
        > > > with
        > > > > the get{} method. this works fine, but the problem is, where do i[/color][/color]
        > store[color=green][color=darkred]
        > > > the
        > > > > string, that i don't lose it. i mean, how can i store the decrypted[/color]
        > > string[color=darkred]
        > > > > in the variable, without reading it each time from the file and[/color]
        > > decrypting[color=darkred]
        > > > > it. i want to store it in the private variable and it should always[/color][/color][/color]
        be[color=blue][color=green][color=darkred]
        > > > > there, as long as the application is running.
        > > > >
        > > > > any ideas?
        > > > >
        > > > > Thanks
        > > > >
        > > > >
        > > >
        > > >[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        Working...