0

I am not sending any sensitive or security information in the query string. I am currently using Base64Encoding along with MD5 Hash. I want to shorten my url as far as possible.

For Eg.:

http://example.com/?Data=U2VhcmNoVHlwZT0yfEJvZHlTdHlsZUlEcz0tMXxUcmFuc0lEPTE0fFRyYW5zVHlwZUlEcz0tMXxGdWVsSUQ9Mzl8RnVlbFR5cGVJRHM9LTF8TWFrZUlEcz0tMXxNb2RlbElEcz0tMXxTb3J0UGFyYW1lbnRlcj1SZXZpZXdDb3VudHxGZWF0dXJlSURzPS0x-swICu07nyN1PmTT897QG%2bA%3d%3d

Kapil Khandelwal
  • 15,958
  • 2
  • 45
  • 52
  • 1
    `Base64Encoding` adds about 30% to the size of the encoded string. You are better off just using the string as is. – Oded May 26 '12 at 08:59
  • Thanks @Oded, I know that sending as is the best option. But I do not want user to do any manipulation in the query string. So, I am looking for another option to shorten the url as far as possible. – Kapil Khandelwal May 26 '12 at 09:25
  • 1
    You can still send as is but append the hash - rehash on the other end and compare the hashes (use a salt so the user can't simply calculate a new hash and send that as well). – Oded May 26 '12 at 09:35
  • do you just want to display the shortened url or you want to use a shortened one everywhere. if it's the latter one, i think you are looking for something like base36 for alphabets. but keep in mind that not all characters are valid on url so you don't have a lot of options here. – Ray Cheng May 26 '12 at 09:42
  • something to look at... http://stackoverflow.com/questions/4144704/lossless-compression-method-to-shorten-string-before-base64-encoding-to-make-it – Ray Cheng May 26 '12 at 09:49
  • or http://pp19dd.com/2011/10/query-string-limits-encoding-hundreds-of-checkboxes-with-rle/#demo – Ray Cheng May 26 '12 at 10:03

2 Answers2

2

If the data is not sensitive, you shouldn't be encrypting it, in particular, not if you want to save space. Encryption will normally only make the string longer.

This is also true to most encodings.

You may want to compress the string, using Zip of 7z, which, depending on the size of the string and the variability in it, may give you good results. You can URL encode the resulting byte[].

You will need to test the different options and see what gives you the best results (though simply sending the string as is may be your best option).

Oded
  • 489,969
  • 99
  • 883
  • 1,009
0

if you don't mind depending on another system, try tinyurl.

http://tinyurl.com/api-create.php?url=http://example.com?Data=blahblah

Ray Cheng
  • 12,230
  • 14
  • 74
  • 137
  • Do you understand that the tinyurl make redirect to the same huge url ? The tinyurl is not shorten the url, is just a shortcut for hidden url, or write them down more easy, or type them on some page. The tiny url is not short the real url. – Aristos May 26 '12 at 09:34
  • @Aristors, valid point. but i was assuming OP just want to display the url so tinyurl makes it look cleaner. – Ray Cheng May 26 '12 at 09:39
  • Even so, it's say `Data=`, how dynamic data can be in real time made tinyUrl ? Can you see that this is impossible ? – Aristos May 26 '12 at 09:44
  • @Aristos, it's possible. first, construct the full url. second, make a http request to tinyurl.com with the url. lastly, receive the http response from tinyurl and the short url is there to use. – Ray Cheng May 26 '12 at 09:47
  • @RayCheng I am looking to shortened dynamic URL QueryString. I am not looking for any sort of redirection using short url. – Kapil Khandelwal May 26 '12 at 10:15
  • @KapilKhandelwal, what's the original form of "Data"? is it binary or plain string? – Ray Cheng May 26 '12 at 15:31