two way encryption algorithm

sj1187534

Centurion
Joined
Jun 10, 2003
Messages
108
Location
Dallas, Houston, etc.etc.
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
 
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.
 
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
 
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 ?)
 
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
 
Encoding

Wasn't damn able to find a suitable function so I build ya one

C#:
[/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:
 
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
 
Back
Top