.NET Answers

ASP.NET, HTML, CSS, Visual Studio, CSharp, VB.NET and other programming items of interest.
Subscribe
  • Home
  • About Me
  • Advertising
  • Click Here to Ask a question
    • Privacy Policy
  • Site Map

Base-64 as URL Parameter

November 13, 2008 By: Dave

other-096 Yesterday, I was working on an application that passes encrypted data as a URLEncoded parameter on to another page.

The problem we were having with this code was that the code would occasionally give us the error, “Invalid Length for a Base-64 char array” when the code was converting the parameter back to a byte array so that it could decrypt it.

What was even more puzzling is that the exact same code run from two different computers would produce two different results.  So it wasn’t exactly data-specific.

As we were looking into the problem further, we noticed that the only difference between the URLs that were working and the URLs that were not is that the character sequence %2b had been replaced by a plus sign in the browser’s address bar.  It turns out that the character sequence %2b is the URLEncoded value for the plus sign.  And the plus sign is the URLEncoded value for a space.

But a space character doesn’t belong in a Base-64 encoded string.  It is an invalid character.

Could it be that the browser where this error is occurring is being too smart and the result is that by the time the Base-64 encoded parameter gets to the decoding code, there is a space?

Time to break out the debugger.  Sure enough–that is what seems to be happening.  So the simple solution is to write some replace code right before the Convert.FromBase64String() code to replace all spaces with plus signs.

Once we did that, it all worked as expected again.

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

Most Commented Post

  • Object Oriented Programming has Failed Us
  • Microsoft’s Biggest Mistake with ASP.NET
  • WordPress w/ Forms Authentication on IIS6
Bookmark to:

Add to Del.icio.us Add to digg Add to DotNetKicks Add to DZone Add to Facebook Add to Slashdot Add to Stumble Upon Add to Technorati
Hide Sites
Tags: %2b, base-64, base64, urlencoding

One Response to “ Base-64 as URL Parameter ”

  1. # 1 Varun Kumar Says:
    December 6th, 2008 at 7:56 am

    Hi ..

    This finally helped me to get out of problem. I already had a solution, but this gave good picture of the problem.

    Thanks,
    Varun Kumar.

← jQuery Looks like XPath
Professional ASP.NET 3.5: In C# and VB →
  • Search

  • Subscribe

    U COMMENT
    I FOLLOW

    Subscribe in a reader

    OR

    Subscribe via e-mail

    Enter your email address: 

    Delivered by FeedBurner

     

  • Follow Me

    • Twitter
    • FaceBook
    • Digg
    • StumbleUpon
    • Propeller
    • Delicious
    • Plaxo

     

  • Recent Posts

    • ASUS Eee PC 1005HA-PU1X-BK Black Netbook
    • jQuery – Date Picker
    • Using VB.NET From CSharp
    • iTextSharp – Adding Images
    • Hungarian Notation – Use What Works, Spit Out The Bones
    • Pre Order Windows 7
    • jQuery Dialog – With Validation Controls
    • iTextSharp – The easy way
    • Structure of my ASP.NET Web Applications
    • 35% Off Accronis True Image 2009 Home
    • VB.NET Hide Module Name
    • ASP.NET/VB.NET – Video Training
    • Does jQuery Make Us Lazy?
    • PDFs Using iTextSharp
    • Programming SEO – Ping



  • Advertise on this site through Lake Quincy Media
  • DotNetNuke Sponsor

     

    Most Valuable Blogger
  • Sponsor

  • Categories

    • Advanced CSharp
    • Advanced VB.NET
    • ASP.NET MVC
    • Did you know
    • DotNetNuke – Module Development
    • DotNetNuke – Skinning
    • internationalization
    • iTextSharp
    • jQuery
    • none
    • Seach Engine Optimization
    • Silverlight
    • SQL For Programmers
    • Twitter
    • winforms
  • Cloud

    .net ajax architecture asp.net book books containers csharp css dal dataset datasets dotnetnuke events gridview images internationalization internet explorer javascript jQuery json linq listview modules ms-sql MVC objectdatasource programming reflection seo Silverlight skinning sql testing tsql tutorial Twitter twitterizer vb.net video view Vista visual studio webservice WordPress
  • Archives

    • July 2009
    • June 2009
    • May 2009
    • April 2009
    • March 2009
    • February 2009
    • January 2009
    • December 2008
    • November 2008
    • October 2008
    • September 2008
    • August 2008
    • July 2008
    • June 2008
    • May 2008
    • April 2008
    • March 2008
    • February 2008
    • January 2008
    • December 2007
    • November 2007
    • October 2007
  • Meta

    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org
    • Privacy Policy
  • Calendar

    November 2008
    S M T W T F S
    « Oct   Dec »
     1
    2345678
    9101112131415
    16171819202122
    23242526272829
    30  
  • Blogroll

    • Alvin Ashcraft’s Morning Dew
    • ASP.NET Consulting
    • Life Hacker
    • Remember Anything
    • The Price of Their Toys
    • Uncategorized Thought


.NET Answers © 2007 - 2008 All Rights Reserved.
Entries and Comments.