Wrox Programmer Forums
|
BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio
This is the forum to discuss the Wrox book ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solution by Vincent Varallo; ISBN: 9780470396865
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 16th, 2009, 03:51 PM
Registered User
 
Join Date: Oct 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 4 Query String

Hi

I am trying to implement encryption & decryption of query string following the steps as discussed in chapter 4 but the only difference is in the book only one value is encrypted & decrypted while in my case I am using 3 values.Encryption part is working fine but when I am trying to decrypt to get the query values I am getting an error which says

Invalid character in a Base-64 string.


Here is code for Encryption :

Code:
Dim collection As New NameValueCollection
            collection = System.Web.HttpUtility.ParseQueryString("Value=" + Name + "&PosNbr=" + PosNbr + "&TrackAppID=" + 34)
EncryptQueryString(collection)
when I try to decrypt I am getting the above error


Any help would be appreciated.
 
Old October 19th, 2009, 02:05 PM
Authorized User
 
Join Date: Apr 2009
Posts: 41
Thanks: 1
Thanked 2 Times in 2 Posts
Default

At a glance (without the book handy or source code handy), might it have something to do with the value you're encrypting, and not the decryption?

Looking at the code you pasted, I noticed you have a 34 (as a literal number) at the end of the argument passed into ParseQueryString. ParseQueryString expects a string - so I'm curious as to how you even got the code to run? I would have expected a compile error because of the 34....

Tim
 
Old October 21st, 2009, 12:39 PM
Authorized User
 
Join Date: Mar 2008
Posts: 62
Thanks: 1
Thanked 3 Times in 3 Posts
Send a message via Yahoo to kalel_4444
Default

I found myself needing to encrypt/decrypt multiple querystring parameters quite often so I created a simple method that will decrypt the values and set them to strings, maybe this will help.
Remember, as Corsair commented, you must convert your integers to strings before encrypting.

// Here's the method (I put this in my BasePage so all pages have access to this).
Code:
public string GetDecryptedValue(string queryString)
{
   // Decrypt the query string
   NameValueCollection collection = DecryptQueryString(Request.QueryString.ToString());

   if (collection == null)
   {
      return null;
   }
   else
   {
      // Get string value
      string value = collection[queryString];

      if (string.IsNullOrEmpty(value))
      {
         return null;
      }
      else
      {
         return value;
      }
   }
}
// Here's a sample of using it.
Code:
// Query string values
string field1 = "value1";
string field2 = "value2";
string field3 = "value3";

// Encrypt the query strings
string Url = "page.aspx" + EncryptQueryString("f1=" + field1 + "&f2=" + field2 + "&f3=" + field3);

// Decrypt query strings
string field1 = GetDecryptedValue("f1");
string field2 = GetDecryptedValue("f2");
string field3 = GetDecryptedValue("f3");
Hope this helps,
Ronnie
The Following User Says Thank You to kalel_4444 For This Useful Post:
ZeroFactorial (October 23rd, 2009)
 
Old October 26th, 2009, 12:16 PM
Authorized User
 
Join Date: Mar 2009
Posts: 79
Thanks: 4
Thanked 4 Times in 4 Posts
Default

Kalel,

I think you provided a very usable and alternative solution to the problem at hand. Much appreciated.
 
Old October 26th, 2009, 12:22 PM
Authorized User
 
Join Date: Mar 2009
Posts: 79
Thanks: 4
Thanked 4 Times in 4 Posts
Default

Kalel,

I think you provided a very usable and alternative solution to the problem at hand. Much appreciated.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Query string value SKhna ASP.NET 2.0 Basics 1 March 17th, 2008 07:27 AM
hide query string Xeon-Yk Beginning PHP 1 May 11th, 2007 03:13 AM
Query String Baby_programmer ASP.NET 1.0 and 1.1 Basics 3 December 24th, 2004 11:14 AM
Query String Nitin_sharma VBScript 1 December 16th, 2004 07:58 AM
SQL Query String mrideout BOOK: Beginning ASP.NET 1.0 1 September 22nd, 2004 02:29 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.