Click here to Skip to main content
15,074,987 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:


i am encrypt my  query string using from Authentication. my code is pasted below. is this method is good or not.

please help me to find out.

  public static string Encrypt(string encryptQuery)
        FormsAuthenticationTicket tk = 
                   new FormsAuthenticationTicket(encryptQuery, false, 30);
        return FormsAuthentication.Encrypt(tk);

i get encripted string using this method  like photos.aspx?aid=3306F85765AA9E9CA5F41AA0269BE6F13F6DCD51<br />EE419DF1E4C711CE22671B617C396C1DEC67089FEE19616FC1D1E808ED<br />C9287A8A10213D40D51F900363A243 

and working properly without any errors.

But i don't know is this a correct method to encrypt. 



thank you all, i think my method also a correct answer  to encrypt and decrypt string 

 public static string Decrypt(string decritptext)
        FormsAuthenticationTicket tk = FormsAuthentication.Decrypt(decritptext);
        return tk.Name.ToString();

this is my method to decrypt.

Updated 25-Nov-09 4:33am

I think the best way is how ASP.NET handles this.

ASP.NET actually encrypts the viewstate into SHA1(by default) for tamper proffing, which you can easily configure to 3DES, MD5 or AES based on your requirement. After it applies encryption, it then Converts it to Base64 stream and embeds into the body.

You might also use any encryption and convert it to Base64.

For Url's It is better to use HttpUtility.UrlEncode(url) before doing redirection.

Hope you will like the solution.


If it works, then I would assume that means it is correct.  The method you're calling is called 'encrypt', so that is obviously what it is doing.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900