encrypting query string

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

    #1

    encrypting query string

    I'am sending some data by the querystring. But I don't want it to be
    seen exactly because of security reasons. Is there a way to encrypt it
    and later decrypt when reading the querystring...?
    I would be very happy with some sample code.

  • Munsifali Rashid

    #2
    Re: encrypting query string

    It's generally a bad idea to send any sensitive data using the querystring,
    for security purposes.

    You'll need to encrypt using the System.Security .Cyptography classes. What
    you can do is use RC4 encryption to encrypt your string, and then convert it
    to Hex so it can safely be passed in the querystring.

    I've done this in classic ASP, but haven't got round to converting it to
    ..net yet, so unfortunately I don't have a code sample. If you'd like to see
    the classic ASP version, let me know.

    Hope this helps,

    Mun




    "Onur Bozkurt" <onur.bozkurt@ß ofthome.net> wrote in message
    news:OzJbesRUDH A.1588@TK2MSFTN GP11.phx.gbl...[color=blue]
    > I'am sending some data by the querystring. But I don't want it to be
    > seen exactly because of security reasons. Is there a way to encrypt it
    > and later decrypt when reading the querystring...?
    > I would be very happy with some sample code.[/color]


    Comment

    • Kevin Spencer

      #3
      Re: encrypting query string

      The real problem with this situation is that he wants to encrypt data and
      then put it into the Query String. If that data controls the functionality
      of the page, it doesn't matter whether it's encrypted or not. The URL will
      still invoke the functionality in the page that the Query String parameter
      specifies, regardless of the user's ability to understand it.

      --
      HTH,

      Kevin Spencer
      Microsoft MVP
      ..Net Developer
      All hotels in Benidorm. The best selection of Benidorm hotels with reviews and maps. Book in advance and save.

      Big things are made up of
      lots of little things.

      "Munsifali Rashid" <mun@**RemoveTo Reply**vefuk.co m> wrote in message
      news:uooZEFSUDH A.1992@TK2MSFTN GP12.phx.gbl...[color=blue]
      > It's generally a bad idea to send any sensitive data using the[/color]
      querystring,[color=blue]
      > for security purposes.
      >
      > You'll need to encrypt using the System.Security .Cyptography classes.[/color]
      What[color=blue]
      > you can do is use RC4 encryption to encrypt your string, and then convert[/color]
      it[color=blue]
      > to Hex so it can safely be passed in the querystring.
      >
      > I've done this in classic ASP, but haven't got round to converting it to
      > .net yet, so unfortunately I don't have a code sample. If you'd like to[/color]
      see[color=blue]
      > the classic ASP version, let me know.
      >
      > Hope this helps,
      >
      > Mun
      >
      >
      >
      >
      > "Onur Bozkurt" <onur.bozkurt@ß ofthome.net> wrote in message
      > news:OzJbesRUDH A.1588@TK2MSFTN GP11.phx.gbl...[color=green]
      > > I'am sending some data by the querystring. But I don't want it to be
      > > seen exactly because of security reasons. Is there a way to encrypt it
      > > and later decrypt when reading the querystring...?
      > > I would be very happy with some sample code.[/color]
      >
      >[/color]


      Comment

      • Onur Bozkurt

        #4
        Re: encrypting query string

        I couldn't understand what exactly you wan't to say because of my poo
        english. You mean is it still unsecure.?
        Is there a way to do this in a more secure way...?

        Kevin Spencer wrote:
        [color=blue]
        > The real problem with this situation is that he wants to encrypt data and
        > then put it into the Query String. If that data controls the functionality
        > of the page, it doesn't matter whether it's encrypted or not. The URL will
        > still invoke the functionality in the page that the Query String parameter
        > specifies, regardless of the user's ability to understand it.
        >
        >[/color]

        Comment

        • Kevin Spencer

          #5
          Re: encrypting query string

          It would be better to store sensitive information on the server, and avoid
          it going out to the client in any way whatsoever.

          --
          HTH,

          Kevin Spencer
          Microsoft MVP
          ..Net Developer
          All hotels in Benidorm. The best selection of Benidorm hotels with reviews and maps. Book in advance and save.

          Big things are made up of
          lots of little things.

          "Onur Bozkurt" <onur.bozkurt@ß ofthome.net> wrote in message
          news:u12WaMTUDH A.3640@tk2msftn gp13.phx.gbl...[color=blue]
          > I couldn't understand what exactly you wan't to say because of my poo
          > english. You mean is it still unsecure.?
          > Is there a way to do this in a more secure way...?
          >
          > Kevin Spencer wrote:
          >[color=green]
          > > The real problem with this situation is that he wants to encrypt data[/color][/color]
          and[color=blue][color=green]
          > > then put it into the Query String. If that data controls the[/color][/color]
          functionality[color=blue][color=green]
          > > of the page, it doesn't matter whether it's encrypted or not. The URL[/color][/color]
          will[color=blue][color=green]
          > > still invoke the functionality in the page that the Query String[/color][/color]
          parameter[color=blue][color=green]
          > > specifies, regardless of the user's ability to understand it.
          > >
          > >[/color]
          >[/color]


          Comment

          • Tarren

            #6
            Re: encrypting query string

            You are assuming the program will understand the querystring and will be
            able to decrypt it and run the logic.

            But if the key is in the session variable, then a new person, even with the
            url, would not be able to run the program because the server would unable to
            decrypt the info without the key in the session variable.

            It does not matter if the user can/cannot understand the querystring. If
            the server cannot understand the querystring at a later time, then the
            problem is solved, no?

            Would this work?


            "Kevin Spencer" <kevin@takempis .com> wrote in message
            news:OlC99zUUDH A.1556@TK2MSFTN GP10.phx.gbl...[color=blue]
            > Here's the thing (thought I explained it earlier!) - The query string is
            > used to pass information to the page that will enable or run some
            > functionality in that page. Regardless of whether the user can understand
            > the query string or not, all he/she needs to do is to paste the URL with[/color]
            the[color=blue]
            > query string into his/her browser, and voila! the page is run.
            >
            > --
            > HTH,
            >
            > Kevin Spencer
            > Microsoft MVP
            > .Net Developer
            > http://www.takempis.com
            > Big things are made up of
            > lots of little things.
            >
            > "Tarren" <noemailpleas e> wrote in message
            > news:eQU3hOUUDH A.3796@tk2msftn gp13.phx.gbl...[color=green]
            > > Could you do this?
            > >
            > > Encrypt the query string and store the private key as a session[/color][/color]
            variable?[color=blue][color=green]
            > > so copying the querystring from the url bar and pasting in a new session
            > > would be useless since there would be no key to decrypt it and it would[/color]
            > just[color=green]
            > > read as garbage text?
            > >
            > > I am assuming here that the requirement is that this data must be in a[/color]
            > query[color=green]
            > > string. Could the above approach work? Anyone have experience with
            > > something of that nature?
            > >
            > >
            > >
            > > "Onur Bozkurt" <onur.bozkurt@ß ofthome.net> wrote in message
            > > news:u12WaMTUDH A.3640@tk2msftn gp13.phx.gbl...[color=darkred]
            > > > I couldn't understand what exactly you wan't to say because of my poo
            > > > english. You mean is it still unsecure.?
            > > > Is there a way to do this in a more secure way...?
            > > >
            > > > Kevin Spencer wrote:
            > > >
            > > > > The real problem with this situation is that he wants to encrypt[/color][/color][/color]
            data[color=blue][color=green]
            > > and[color=darkred]
            > > > > then put it into the Query String. If that data controls the[/color]
            > > functionality[color=darkred]
            > > > > of the page, it doesn't matter whether it's encrypted or not. The[/color][/color][/color]
            URL[color=blue][color=green]
            > > will[color=darkred]
            > > > > still invoke the functionality in the page that the Query String[/color]
            > > parameter[color=darkred]
            > > > > specifies, regardless of the user's ability to understand it.
            > > > >
            > > > >
            > > >[/color]
            > >
            > >[/color]
            >
            >[/color]


            Comment

            • Onur Bozkurt

              #7
              Re: encrypting query string

              Let me explain it from the beginning.

              This is an e-commerce site without a ssl certificate. So when the user ready
              to give his/her credit card number I will redirect the user to a new
              web-site with a ssl certificate.
              This wasn't my choice but it should be in this way and can't be changed.

              So when redirecting the user I should send the orderid, userid, amount will
              be paid,.... to the new page. But I don't want these values to be seen
              clearly.




              Comment

              • Munsifali Rashid

                #8
                Re: encrypting query string

                Definitely do-able. You could encrypt a string using a private key, and
                then hex the value (as often, encrypted strings are non-ascii, and you'll
                end up with a very messy URL). Pass the hex in your querystring, and then
                decrypt it on the other end. The querystring is encrypted, so if the user
                messes with it, the server will simply be unable to decipher it on the
                receiving end and discard it.

                I've converted a class I wrote in class ASP to do this, to ASP.NET (though
                it's not using the new security classes, yet). If you're interested in
                this, drop me a line.

                Mun




                "Tarren" <noemailpleas e> wrote in message
                news:utl5xwVUDH A.2192@TK2MSFTN GP09.phx.gbl...[color=blue]
                > You are assuming the program will understand the querystring and will be
                > able to decrypt it and run the logic.
                >
                > But if the key is in the session variable, then a new person, even with[/color]
                the[color=blue]
                > url, would not be able to run the program because the server would unable[/color]
                to[color=blue]
                > decrypt the info without the key in the session variable.
                >
                > It does not matter if the user can/cannot understand the querystring. If
                > the server cannot understand the querystring at a later time, then the
                > problem is solved, no?
                >
                > Would this work?[/color]


                Comment

                • Munsifali Rashid

                  #9
                  Re: encrypting query string

                  Why not post the form directly to the SSL site?

                  Alternatively, break your order into two steps. The first when the order is
                  written to the database on your end, and then have a form with a bunch of
                  hidden fields with the Order ID, User ID, Amount, etc and a submit button to
                  the SSL Site saying something like "Click here to pay securely with your
                  credit card".

                  The form would be submitted to the SSL site, which could use it as required,
                  and the user would be able to enter their credit card details to complete
                  the transaction.

                  If you need to do it without user interaction - i.e. you cant implement the
                  above scenario where the user has to click a button, then you could, from
                  code dynamically build a form with hidden fields containing the data you
                  need to pass across to the SSL site, and then use JavaScript to
                  automatically post this form.

                  Hope this helps,

                  Mun





                  "Onur Bozkurt" <destek@hemente knoloji.com> wrote in message
                  news:eflkQybUDH A.1196@TK2MSFTN GP10.phx.gbl...[color=blue]
                  > Let me explain it from the beginning.
                  >
                  > This is an e-commerce site without a ssl certificate. So when the user[/color]
                  ready[color=blue]
                  > to give his/her credit card number I will redirect the user to a new
                  > web-site with a ssl certificate.
                  > This wasn't my choice but it should be in this way and can't be changed.
                  >
                  > So when redirecting the user I should send the orderid, userid, amount[/color]
                  will[color=blue]
                  > be paid,.... to the new page. But I don't want these values to be seen
                  > clearly.[/color]


                  Comment

                  • Munsifali Rashid

                    #10
                    Re: encrypting query string

                    Definitely do-able. You could encrypt a string using a private key, and
                    then hex the value (as often, encrypted strings are non-ascii, and you'll
                    end up with a very messy URL). Pass the hex in your querystring, and then
                    decrypt it on the other end. The querystring is encrypted, so if the user
                    messes with it, the server will simply be unable to decipher it on the
                    receiving end and discard it.

                    I've converted a class I wrote in class ASP to do this, to ASP.NET (though
                    it's not using the new security classes, yet). If you're interested in
                    this, drop me a line.

                    Mun




                    "Tarren" <noemailpleas e> wrote in message
                    news:utl5xwVUDH A.2192@TK2MSFTN GP09.phx.gbl...[color=blue]
                    > You are assuming the program will understand the querystring and will be
                    > able to decrypt it and run the logic.
                    >
                    > But if the key is in the session variable, then a new person, even with[/color]
                    the[color=blue]
                    > url, would not be able to run the program because the server would unable[/color]
                    to[color=blue]
                    > decrypt the info without the key in the session variable.
                    >
                    > It does not matter if the user can/cannot understand the querystring. If
                    > the server cannot understand the querystring at a later time, then the
                    > problem is solved, no?
                    >
                    > Would this work?[/color]


                    Comment

                    • Munsifali Rashid

                      #11
                      Re: encrypting query string

                      Why not post the form directly to the SSL site?

                      Alternatively, break your order into two steps. The first when the order is
                      written to the database on your end, and then have a form with a bunch of
                      hidden fields with the Order ID, User ID, Amount, etc and a submit button to
                      the SSL Site saying something like "Click here to pay securely with your
                      credit card".

                      The form would be submitted to the SSL site, which could use it as required,
                      and the user would be able to enter their credit card details to complete
                      the transaction.

                      If you need to do it without user interaction - i.e. you cant implement the
                      above scenario where the user has to click a button, then you could, from
                      code dynamically build a form with hidden fields containing the data you
                      need to pass across to the SSL site, and then use JavaScript to
                      automatically post this form.

                      Hope this helps,

                      Mun





                      "Onur Bozkurt" <destek@hemente knoloji.com> wrote in message
                      news:eflkQybUDH A.1196@TK2MSFTN GP10.phx.gbl...[color=blue]
                      > Let me explain it from the beginning.
                      >
                      > This is an e-commerce site without a ssl certificate. So when the user[/color]
                      ready[color=blue]
                      > to give his/her credit card number I will redirect the user to a new
                      > web-site with a ssl certificate.
                      > This wasn't my choice but it should be in this way and can't be changed.
                      >
                      > So when redirecting the user I should send the orderid, userid, amount[/color]
                      will[color=blue]
                      > be paid,.... to the new page. But I don't want these values to be seen
                      > clearly.[/color]


                      Comment

                      Working...