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

  • SEARCH
  • Home
  • 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 209191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:53:35+00:00 2026-05-11T17:53:35+00:00

I am facing a weird problem: I am encrypting the contents of a cookie.

  • 0

I am facing a weird problem:

I am encrypting the contents of a cookie.

My code works fine when I run it in Visual Studio, but gives me a “Bad Request, HTTP Error 400. The request is badly formed.” when I run it from the server.

Here is the class for encryption Encrypt Cook.cs, resides in app_code:

public class EncryptCook
{
public EncryptCook()
{
    //
    // TODO: Add constructor logic here
    //
}

public  string EncryptString(string data)
{
    try
    {
        string encryptString = "";
        if (data != "")
        {
            char a;
            int key = Convert.ToInt16(DateTime.Now.Day);
            int j = 0;

            for (int i = 0; i < data.Length; i++)
            {

                j = (int)data[i];
                j = j + key;
                a = (char)j;
                encryptString = encryptString + Convert.ToString(a);

            }
        }
        return encryptString;
    }
    catch
    {
        return "";
    }
}

public   string DeEncryptString(string data)
{
    try
    {
        string encryptString = "";
        if (data != "")
        {

            char a;
            int j = 0;
            int key = Convert.ToInt16(DateTime.Now.Day);
            for (int i = 0; i < data.Length; i++)
            {

                j = (int)data[i];
                j = j - key;
                a = (char)j;
                encryptString = encryptString + Convert.ToString(a);

            }
        }
        return encryptString;
    }
    catch
    {
        return "";
    }

}

Pretty simple, it takes a string, extracts the characters from it and replaces the character with another one, for example, given “a” and that todays date is 13, it will replace it with the 13th character after “a”, i.e. “m”.

Here is my login control:

protected void Button1_Click(object sender, EventArgs e)
{
//code for retrieving user, which works fine
EncCook cook=new EncCook();
HttpCookie cookie = new HttpCookie("loginstatus");
            cookie["userid"] =cook.EncryptString(name);
            cookie["username"] = cook.EncryptString(doctor);
            cookie["email"] = cook.EncryptString(email);
            cookie["address"] = cook.EncryptString(address);
 Response.Cookies.Add(cookie);
}

Well, this code works fine in the local machine, but gives me a “Bad Request HTTP Error 400. The request is badly formed.” error.

I think that it’s because of the encoding, but I am not sure, like if its 20 today then ~ + 20 will look like a box character.

Thanks

  • 1 1 Answer
  • 3 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-05-11T17:53:36+00:00Added an answer on May 11, 2026 at 5:53 pm

    Please don’t use home-brewed encryption. It can only end in embarrassment. And if you catch an exception, you should probably rethrow it or return null, not the empty string. The error is likely because your so-called encryption is creating byte sequences that are not valid in the current charset.

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

Sidebar

Related Questions

I'm writing Unit test cases in Visual Studio 2008. I'm facing a weird problem.
I am facing a weird problem. While browsing the C code of a project,
this time, I'm facing a really weird problem. I've the following code: $xml =
I'm facing a weird problem. I looked around all over stackoverflow.com and elsewhere, but
I am facing a weird problem to get the Quartz library run in my
It may sound weird but I am facing a problem in calling a same
Brand new to android and facing a weird problem.Check out the code below FirstActivity.java:
weird problem or bug. I'm using the jQuery Form Plugin and it works fine
I am facing a weird problem on BlackBerry JDE 4.2.0 and the 8100 simulator
I m facing a weird problem with submodules in a bare repo. I illustrate

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.