System.Security.Cryptography

  • Thread starter Thread starter tascien
  • Start date Start date
T

tascien

What i want to do is really simple...

Encrypt all my querystrings, in the website. Do want to show something
like this:

UserID=833774

want to show:

uid=09SDSOIFDOIFIIDOIFOIDFOIOIFD

some kind of encrypted string that requires a password to decrypt it.

the examples shown here:

http://msdn.microsoft.com/library/d...pcongeneratingkeysforencryptiondecryption.asp

are cumbersome...

1. The Encrypt returns bytes instead of the string... (Why not return a
string...)
2. Decrypt is doing some TCP/IP connections.... (what's that for???)

Anybody can point me to a better example?

Tascien
 
Thanks for the example, but when i try to write out the ciphered bytes
in text, I get strange results...

System.text.encoding.utf8.GetString(ciphered) print out something like
this:

Z2QC.%▲WA⌂t¶upPJ<: Fz↓??w♀Um♣3
?H$2+TPC'☻9♂(&◄l&E?Dc;,5▬rNQp$h?♫wXC?vNGY

I need something i can use ain a query string...
 
tascien said:
Thanks for the example, but when i try to write out the ciphered bytes
in text, I get strange results...

System.text.encoding.utf8.GetString(ciphered) print out something like
this:

Z2QC.%?WA?t?upPJ<: Fz???w?Um?3
?H$2+TPC'?9?(&?l&E?Dc;,5?rNQp$h??wXC?vNGY

Yes - and you should expect that, because you were putting arbitrary
data into it. (There's no guarantee that it's even a valid UTF-8-
encoded string at all.)
I need something i can use ain a query string...

Use Convert.ToBase64String. You might want to replace / with * and +
with - to make it more URL-encoding-friendly.
 
Or use HttpContext.Server.HtmlEncode once you have the Base64 string...so:

1. Encrypt to bytes
2. Convert to Base64 string
3. Encode Base64 string for use in querystring

HTH,
Kent
 
thanks all. then only problem with this encryption is the 58 chars
limitation...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top