sj1187534 Posted April 13, 2004 Posted April 13, 2004 Hi...Does anyone know any two-way encryption algoritm. I have been trying to use the DES and the TripleDES algorithms but the problem with these is I am not able to pass the encrypted string through the querystring as the encrypted string has some special characters in it. Any ideas? For instance when I am trying to encrypt the number "126" using DES encryption method, the encrypted string is 'lng0+5+6Utk=' which cannot be passed through the querystring because of the '+' character. I dont know why!! SJ Quote
Administrators PlausiblyDamp Posted April 13, 2004 Administrators Posted April 13, 2004 You could use the system.Web.HttpUtility.HtmlEncode() and system.Web.HttpUtility.HtmlDecode() functions to make the string HTML safe and then convert it back again. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
sj1187534 Posted April 13, 2004 Author Posted April 13, 2004 Hi...It is not working. For some reason, the character '+' in the encoded string is vanishing even when HttpUtility.HtmlDecode() is used on the encrypted string. Is there any significance for the '+' char in the querystring? SJ Quote
Arch4ngel Posted April 13, 2004 Posted April 13, 2004 Maybe HtmlUrlEncode ? Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
sj1187534 Posted April 13, 2004 Author Posted April 13, 2004 Nope...Thats not working either!! SJ Quote
Arch4ngel Posted April 14, 2004 Posted April 14, 2004 HttpUtility.UrlPathEncode(...) then ? If it work... alright...everythings perfect If it doesn't... try bashing your case with a hammer. I heard that it solve most of the problem "into" your computer. :D If none of above work... you'll have to convert char from "+" to %343 (not the right value) you know ? Their ANSI value in integer. (Isn't it ?) Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
sj1187534 Posted April 15, 2004 Author Posted April 15, 2004 Hi..That is not working either. All the encoding and decoding is making the '+' character vanish!!! And I am having this problem for the '+' char alone. I have'nt come across anything else yet. So, I cannot write any code to replace the '+' char with whatever ascii value it has. Do you know any two-way encryption algorithm that does not give any special characters in the encoded string. For ex: the MD5 and SHA1 encryption algorithms returns the encrypted strings in alphabets and numbers only. But both of them are one-way encryption algorithms!! SJ Quote
Arch4ngel Posted April 15, 2004 Posted April 15, 2004 Encoding Wasn't damn able to find a suitable function so I build ya one [/color][/size][size=2][color=#0000ff]public[/color][/size][size=2][color=#0000ff]string[/color][/size][size=2] Encode([/size][size=2][color=#0000ff]string[/color][/size][size=2] str)[/size] [size=2]{[/size] [size=2][color=#0000ff] string[/color][/size][size=2] ret = "";[/size] [size=2] System.Text.Encoding ascii = System.Text.Encoding.ASCII;[/size] [size=2][color=#0000ff] byte[/color][/size][size=2][] bs = ascii.GetBytes(str);[/size] [size=2][color=#0000ff] foreach[/color][/size][size=2]( [/size][size=2][color=#0000ff]byte[/color][/size][size=2] b [/size][size=2][color=#0000ff]in[/color][/size][size=2] bs)[/size] [size=2] {[/size] [size=2] ret += "&" + b + ";";[/size] [size=2] }[/size] [size=2][color=#0000ff] return[/color][/size][size=2] ret;[/size] [size=2]}[/size][size=2] That's it... they are now encoded... find a way now to deencode them :D Other people want me you see what I mean :cool: Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
sj1187534 Posted April 16, 2004 Author Posted April 16, 2004 Hi...Thanks for the code. Infact, my code is working with a small change that I have made. Instead of using Server.URLEncode, I used HTTPUtility.URLEncode when passing the encrypted string into the URL like this: "./sample.aspx?id=" & HttpUtility.UrlEncode(CryptoUtil.EncryptTripleDES(dr.Item("idnum"))) But when I am trying to read from the querystring, I am not using any HTTPUtility.URLDecode. Like this: CInt(CryptoUtil.Decrypt(Request.QueryString("id"))) Everything is working great. Thanks SJ Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.