Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7746583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:18:57+00:00 2026-06-01T10:18:57+00:00

I have a dictionary object which i would like to encrypt, then put it

  • 0

I have a dictionary object which i would like to encrypt, then put it in a querystring, then decrypt it on the other side.

I’m using JavaScriptSerializer for this. Now i’ve tried this on the same page onload, and it worked. So the encrypt/decrypt extension methods im using are working. This leads me to believe there’s some issue going on with the querystring.

e.g.

        var js = new JavaScriptSerializer();
        var d = new Dictionary<string, string>();
        d.Add("ID", "123456");
        d.Add("Name", "HELLO TEST");
        d.Add("Email", "test@email.com");
        var s = js.Serialize(d).EncryptString();
        var ds = js.Deserialize<Dictionary<string, string>>(s.DecryptString());
        @ViewBag.Test = ds["Name"];

In the above example, EncryptString() and DecryptString() are the extension methods i’m using. This works as intended, so it pulls the correct value for "Name".

I run into problems when I put the serialized encrypted string into the querystring then try and decode it.

So on the first page, i have something like this:

        var js = new JavaScriptSerializer();
        var d = new Dictionary<string, string>();
        d.Add("ID", "123456");
        d.Add("Name", "HELLO TEST");
        d.Add("Email", "test@email.com");
        var s = HttpUtility.UrlEncode(js.Serialize(d).EncryptString());

s is then used as the querystring.

On the receiving page, i have this:

public ActionResult Display(string r)
{
        var js = new JavaScriptSerializer();
        var decryptedString = HttpUtility.UrlDecode(r).DecryptString();
        var s = js.Deserialize<Dictionary<string, string>>(decryptedString);
        return View();
}

This throws an error: System.FormatException: Invalid length for a Base-64 char array or string. This errors on the decryptstring line.

I don’t get what’s going on… I’m urlencoding the text before it goes into the querystring, then urldecoding it before it’s deserialized..

EDIT

Figured it out.. I was encrypting it twice…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:18:59+00:00Added an answer on June 1, 2026 at 10:18 am

    Chances are that you don’t need to UrlDecode your string, because MVC will have done that before assigning the value of your r parameter. Try decrypting r directly.

    And of course, I have to issue the warning: what you’re doing here seems like a very bad idea. Whatever you’re trying to accomplish by sending this encrypted dictionary in the URL, there is almost certainly a better way to accomplish it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have a dictionary object contains string keys and values, which
I have a bunch of named value parameters in a Dictionary<string, object> , which
I have a Dictionary object that is formed using a double as its key.
I have an object Dictionary<int, Dictionary<int, Foo> > on one side, and a function
I have an object allStudents = Dictionary<ClassRoom, List<Student>>() In Linq how would I get
I have a generic dictonary which is templated in the following manner: Dictionary<object, IList<ISomeInterface>>
I have this Class which is accepting a Dictionary<string,object> which is been invoked from
I have an Action which returns a partial view, and I would like to
I have a Dictionary of objects I have created in smalltalk, which I am
Possible Duplicate: Modifying .NET Dictionary while Enumerating through it I have a dictionary object

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.